package com.beiye.drivertransport.SubActivity;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.hardware.Camera;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextPaint;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.WindowManager;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.android.frame.view.linearlistview.LinearListView;
import com.beiye.drivertransport.R;
import com.beiye.drivertransport.Video.JZMediaIjk;
import com.beiye.drivertransport.Video.MyJZVideoPlayerStandard;
import com.beiye.drivertransport.activity.TwoBaseAty;
import com.beiye.drivertransport.adapter.CourseDetailRvSubjectApt;
import com.beiye.drivertransport.adapter.CourseDetailSubjectApt;
import com.beiye.drivertransport.bean.CheckBean;
import com.beiye.drivertransport.bean.CourseDetailBean;
import com.beiye.drivertransport.bean.CourseDetailSubjectBean;
import com.beiye.drivertransport.bean.LoginUserBean;
import com.beiye.drivertransport.bean.SignBean;
import com.beiye.drivertransport.bean.UserTcPhoto;
import com.beiye.drivertransport.config.AppInterfaceConfig;
import com.beiye.drivertransport.http.Login;
import com.beiye.drivertransport.safelearn.DailyTrainingExaminationItemActivity;
import com.beiye.drivertransport.safelearn.SpecifiedLearningHomeActivity;
import com.beiye.drivertransport.thirdparty.tbs.SuperFileView2;
import com.beiye.drivertransport.utils.FileParseUtil;
import com.beiye.drivertransport.utils.HelpUtil;
import com.beiye.drivertransport.utils.LogUtils;
import com.beiye.drivertransport.utils.MessageEvent;
import com.beiye.drivertransport.utils.MusicUtils;
import com.beiye.drivertransport.utils.TiShiDialog;
import com.beiye.drivertransport.utils.UserManger;
import com.beiye.drivertransport.utils.Utils;
import com.beiye.drivertransport.view.CircularProgressView;
import com.githang.statusbar.StatusBarCompat;
import com.google.gson.Gson;
import com.squareup.picasso.Picasso;

import net.frakbot.jumpingbeans.JumpingBeans;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;


import butterknife.OnClick;
import cn.jzvd.JZDataSource;
import cn.jzvd.Jzvd;
import cn.jzvd.JzvdStd;
import es.dmoral.toasty.Toasty;
import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;

//驾驶员课程超市的学习界面
public class CourseDetailsActivity extends TwoBaseAty implements SurfaceHolder.Callback, MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener, MediaPlayer.OnPreparedListener {


    WebView web;

    LinearLayout le_parement;

    ImageView img_Courseback;

    ImageView img_course2;

    RecyclerView lv_coursedetail;

    MyJZVideoPlayerStandard jcVideoPlayerStandard;

    TextView tv_courseName;


    TextView tv_courseLength;

    TextView tv_course11;//请回答

    TextView tv_cumulativeLength;//累计时长

    ImageView show_camera_iv;//显示第一张照片

    ImageView show_camera_iv1;//显示照片第二张

    ImageView show_camera_iv2;//显示照片第三张

    ImageView show_camera_iv3;//显示照片第四张

    ImageView show_camera_iv4;//显示照片第五张

    SurfaceView surfaceSv;//预览照片

    TextView tv_sure;

    RelativeLayout re_course;//隐藏按钮

    LinearLayout totalle_course;//照片布局

    LinearLayout re_course1;//照片布局

    TextView img_course;

    TextView tv_course12;

    RelativeLayout re_course2;//隐藏语音

    ImageView playOrPauseFab;//播放

    SeekBar musicSeekBar;//

    TextView tv_playorpause;//播放与暂停显示

    TextView progress_tv;//播放进度时间

    TextView total_tv;//播放总时间
    private MediaPlayer mediaPlayer;
    private MusicHandler musicHandler;
    private AlertDialog mDialog;
    private TextView mOffTextView;
    private static final String TAG = CourseDetailsActivity.class.getSimpleName();
    private static final int MEDIA_TYPE_IMAGE = 1;
    private Timer mOffTime;

    private TimerTask timerTask;
    private Handler mOffHandler = new Handler() {
        public void handleMessage(Message msg) {
            if (msg.what > 0) {
                ////动态显示倒计时
                downtime.setText(msg.what + "");
            } else {
                ////倒计时结束自动关闭
                if (mPopWindow != null) {
                    downtime.setVisibility(View.GONE);
                    tv_photo.setText("请拍照，继续学习！");
                    tv_photo4.setVisibility(View.GONE);
                    tv_photo1.setText("你未在规定时间内操作");
                    tv_photo.setTextColor(Color.parseColor("#ff8092"));
                    tv_photo2.setVisibility(View.GONE);
                    img_photo.setImageResource(R.mipmap.sorry);
                    //   mPopWindow.dismiss();
                    //  timerTask.cancel();

                }
                // off();////关闭后的操作
                mOffTime.cancel();
            }
            super.handleMessage(msg);
        }
    };


    private long mRecordTime;
    private int formattimecnt;
    Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            int what = msg.what;
            if (what == 0) {
                ////打开界面时累计时长

                SharedPreferences sp1 = getSharedPreferences("CourseDetailsActivity",
                        Context.MODE_PRIVATE);
                String format = sp1.getString("format", "");
                if (format.equals("")) {
                    timerTask = new TimerTask() {
                        int cnt = 0;

                        @Override
                        public void run() {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    String stringTime = getStringTime(cnt++);
                                    tv_cumulativeLength.setText(stringTime);
                                    SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                                            Context.MODE_PRIVATE);
                                    String firsttimestr = getStringTime(firsttime);
                                    SharedPreferences.Editor edit = sp.edit();
                                    edit.putString("firsttime", firsttimestr);
                                    edit.putString("format", stringTime);
                                    edit.commit();
                                    LogUtils.e("format", stringTime);
                                    LogUtils.e("firsttime", firsttimestr);
                                    if (stringTime.equals(firsttimestr)) {

                                        if (setYm.equals("")) {
                                            return;
                                        }
                                        timerTask.cancel();
                                        //tv_pause.setVisibility(View.GONE);
                                        initDialog();
//                                    JZVideoPlayer jzvd = JZVideoPlayerManager.getCurrentJzvd();
//                                    if(jzvd!=null) {
//                                        jzvd.onStatePause();
//                                        JZMediaManager.pause();//暂停
//                                    }


                                    }
                                }
                            });
                        }
                    };
                    timer1.schedule(timerTask, 0, 1000);
                } else {

                    String[] splitformat = format.split(":");
                    String format1 = splitformat[0];
                    String format2 = splitformat[1];
                    String format3 = splitformat[2];
                    int iformat1 = Integer.valueOf(format1);//转int
                    int iformat2 = Integer.valueOf(format2);//转int
                    int iformat3 = Integer.valueOf(format3);//转int
                    int formattime = iformat1 * 3600 + iformat2 * 60 + iformat3 * 1;
                    formattimecnt = formattime;
                    timerTask = new TimerTask() {
                        @Override
                        public void run() {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    String stringTime = getStringTime(formattimecnt++);
                                    tv_cumulativeLength.setText(stringTime);
                                    SharedPreferences sp1 = getSharedPreferences("CourseDetailsActivity",
                                            Context.MODE_PRIVATE);
                                    String firsttimestr = getStringTime(firsttime);
                                    String firsttimestr1 = getStringTime(firsttime1);
                                    LogUtils.e("format", stringTime);
                                    LogUtils.e("firsttimestr", firsttimestr);
                                    LogUtils.e("firsttimestr1", firsttimestr1);
                                    SharedPreferences.Editor edit = sp1.edit();
                                    edit.putString("format", stringTime);
                                    edit.putString("firsttime", firsttimestr);
                                    edit.commit();
                                    String imgurl = sp1.getString("imgurl", "");
                                    if (imgurl.equals("")) {
                                        if (stringTime.equals(firsttimestr)) {
                                            if (setYm.equals("")) {
                                                return;
                                            }
                                            edit.putString("firsttime", firsttimestr);
                                            edit.commit();
                                            timerTask.cancel();
                                            //tv_pause.setVisibility(View.GONE);
                                            initDialog();
                                        } else if (stringTime.equals(firsttimestr1)) {
                                            if (setYm.equals("")) {
                                                return;
                                            }
                                            edit.putString("firsttime", firsttimestr1);
                                            edit.commit();
                                            timerTask.cancel();
                                            //tv_pause.setVisibility(View.GONE);
                                            initDialog();
                                        }
                                    } else {
                                        int courseLength = sp1.getInt("courseLength", 0);
//                                        int courseLengthtime = courseLength * 60;
//                                        String courseLengthtime1 = getStringTime(courseLengthtime);
                                        int num = sp1.getInt("num", 0);
                                        String[] splitformat = stringTime.split(":");
                                        String format1 = splitformat[0];
                                        String format2 = splitformat[1];
                                        String format3 = splitformat[2];
                                        int iformat1 = Integer.valueOf(format1);//转int
                                        int iformat2 = Integer.valueOf(format2);//转int
                                        int iformat3 = Integer.valueOf(format3);//转int
                                        int formattime = iformat1 * 3600 + iformat2 * 60 + iformat3 * 1;
                                        LogUtils.e("退出拍照后计时", stringTime + "/" + num);
//                                        if(formattime==courseLength*60) {
//                                            timerTask.cancel();
//                                        }
                                        if (formattime == courseLength * 60) {
                                            timerTask.cancel();
                                            if (setYm.equals("")) {

                                                TiShiDialog.Builder builder1 = new TiShiDialog.Builder(CourseDetailsActivity.this);
                                                builder1.setMessage("仅查看,不能自动提交");
                                                builder1.setTitle("提示:");
                                                builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                                    public void onClick(DialogInterface dialog, int which) {
                                                        dialog.dismiss();
                                                        //设置你的操作事项

                                                    }
                                                });
                                                builder1.create().show();
                                                return;
                                            }
                                            if (rowsList.size() != 0) {

                                                for (int i = 0; i < rowsList.size(); i++) {
                                                    if (rowsList.get(i).isSelect() == false) {
                                                        TiShiDialog.Builder builder1 = new TiShiDialog.Builder(CourseDetailsActivity.this);
                                                        builder1.setMessage("第" + (i + 1) + "测验题未答，请答题");
                                                        builder1.setTitle("提示:");
                                                        builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                                            public void onClick(DialogInterface dialog, int which) {
                                                                dialog.dismiss();
                                                                ;
                                                                //设置你的操作事项
                                                            }
                                                        });
                                                        builder1.create().show();

                                                        return;
                                                    } else {

                                                        if (rowsList.get(i).isLOOP() == false) {
                                                            TiShiDialog.Builder builder1 = new TiShiDialog.Builder(CourseDetailsActivity.this);
                                                            builder1.setMessage("第" + (i + 1) + "测验题回答错误，请重新答题");
                                                            builder1.setTitle("提示:");
                                                            builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                                                public void onClick(DialogInterface dialog, int which) {
                                                                    dialog.dismiss();
                                                                    ;
                                                                    //设置你的操作事项
                                                                }
                                                            });
                                                            builder1.create().show();


                                                            return;
                                                        }
                                                    }
                                                }
                                                //有测验题有照片自动提交
                                                LoginUserBean userInfo = UserManger.getUserInfo();
                                                String userId2 = userInfo.getData().getUserId();
                                                SharedPreferences sp2 = getSharedPreferences("CourseDetailsActivity",
                                                        Context.MODE_PRIVATE);
                                                int tcsn2 = sp2.getInt("tcsn", 0);
                                                int learnsn2 = sp2.getInt("learnsn", 0);
                                                String orgId2 = sp2.getString("orgId", "");

                                                String firsttimestr2 = sp2.getString("firsttime", "");//第一次抓拍时间
                                                String imgurl1 = sp2.getString("imgurl", "");//第一次拍照图片地址获取
                                                String firsttimesub = firsttimestr2.substring(3, 8);//截取字符串00:00:00变成00:00
                                                List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                                                UserTcPhoto userTcPhoto = new UserTcPhoto();
                                                userTcPhoto.setUrl(imgurl1);
                                                userTcPhoto.setSnapTime(firsttimesub);
                                                photoList.add(userTcPhoto);
                                                Gson gson = new Gson();
                                                String strphotoList = gson.toJson(photoList);
                                                LogUtils.e("strphotoList", strphotoList);
                                                initsuredata(userId2, orgId2, tcsn2, learnsn2, courseLength, photoList);
                                            } else {
                                                //无测验题有照片自动提交
                                                LoginUserBean userInfo = UserManger.getUserInfo();
                                                String userId2 = userInfo.getData().getUserId();
                                                SharedPreferences sp2 = getSharedPreferences("CourseDetailsActivity",
                                                        Context.MODE_PRIVATE);
                                                int tcsn2 = sp2.getInt("tcsn", 0);
                                                int learnsn2 = sp2.getInt("learnsn", 0);
                                                String orgId2 = sp2.getString("orgId", "");

                                                String firsttimestr2 = sp2.getString("firsttime", "");//第一次抓拍时间
                                                String imgurl1 = sp2.getString("imgurl", "");//第一次拍照图片地址获取
                                                String firsttimesub = firsttimestr2.substring(3, 8);//截取字符串00:00:00变成00:00
                                                List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                                                UserTcPhoto userTcPhoto = new UserTcPhoto();
                                                userTcPhoto.setUrl(imgurl1);
                                                userTcPhoto.setSnapTime(firsttimesub);
                                                photoList.add(userTcPhoto);
                                                Gson gson = new Gson();
                                                String strphotoList = gson.toJson(photoList);
                                                LogUtils.e("strphotoList", strphotoList);
                                                initsuredata(userId2, orgId2, tcsn2, learnsn2, courseLength, photoList);
                                            }
                                        }
                                    }

                                }
                            });
                        }
                    };
                    timer1.schedule(timerTask, 0, 1000);
                }
            } else if (what == 2) {
                SharedPreferences sp1 = getSharedPreferences("CourseDetailsActivity",
                        Context.MODE_PRIVATE);

                String format = sp1.getString("format", "");
                if (format.equals("")) {

                    timerTask = new TimerTask() {
                        int cnt = 1;

                        @Override
                        public void run() {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    String stringTime = getStringTime(cnt++);
                                    tv_cumulativeLength.setText(stringTime);
                                    LogUtils.e("format", stringTime);
                                    SharedPreferences sp1 = getSharedPreferences("CourseDetailsActivity",
                                            Context.MODE_PRIVATE);
                                    SharedPreferences.Editor edit = sp1.edit();
                                    edit.putString("format", stringTime);
                                    edit.commit();
                                    int courseLength = sp1.getInt("courseLength", 0);
                                    int courseLengthtime = courseLength * 60;
                                    String courseLengthtime1 = getStringTime(courseLengthtime);

                                    if (stringTime.equals(courseLengthtime1)) {
                                        timerTask.cancel();
                                        if (setYm.equals("")) {

                                            TiShiDialog.Builder builder1 = new TiShiDialog.Builder(CourseDetailsActivity.this);
                                            builder1.setMessage("仅查看,不能自动提交");
                                            builder1.setTitle("提示:");
                                            builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                                public void onClick(DialogInterface dialog, int which) {
                                                    dialog.dismiss();
                                                    ;
                                                    //设置你的操作事项

                                                }
                                            });
                                            builder1.create().show();
                                            return;
                                        }
                                        if (rowsList.size() != 0) {

                                            for (int i = 0; i < rowsList.size(); i++) {
                                                if (rowsList.get(i).isSelect() == false) {
                                                    TiShiDialog.Builder builder1 = new TiShiDialog.Builder(CourseDetailsActivity.this);
                                                    builder1.setMessage("第" + (i + 1) + "测验题未答，请答题");
                                                    builder1.setTitle("提示:");
                                                    builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                                        public void onClick(DialogInterface dialog, int which) {
                                                            dialog.dismiss();
                                                            ;
                                                            //设置你的操作事项
                                                        }
                                                    });
                                                    builder1.create().show();

                                                    return;
                                                } else {

                                                    if (rowsList.get(i).isLOOP() == false) {
                                                        TiShiDialog.Builder builder1 = new TiShiDialog.Builder(CourseDetailsActivity.this);
                                                        builder1.setMessage("第" + (i + 1) + "测验题回答错误，请重新答题");
                                                        builder1.setTitle("提示:");
                                                        builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                                            public void onClick(DialogInterface dialog, int which) {
                                                                dialog.dismiss();
                                                                ;
                                                                //设置你的操作事项
                                                            }
                                                        });
                                                        builder1.create().show();


                                                        return;
                                                    }
                                                }
                                            }
                                            //有测验题无照片自动提交
                                            LoginUserBean userInfo = UserManger.getUserInfo();
                                            String userId2 = userInfo.getData().getUserId();
                                            SharedPreferences sp2 = getSharedPreferences("CourseDetailsActivity",
                                                    Context.MODE_PRIVATE);
                                            int tcsn2 = sp2.getInt("tcsn", 0);
                                            int learnsn2 = sp2.getInt("learnsn", 0);
                                            String orgId2 = sp2.getString("orgId", "");

                                            String firsttimestr2 = sp2.getString("firsttime", "");//第一次抓拍时间
                                            String imgurl1 = sp2.getString("imgurl", "");//第一次拍照图片地址获取
                                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                                            userTcPhoto.setUrl(imgurl1);
                                            userTcPhoto.setSnapTime(firsttimestr2);
                                            photoList.add(userTcPhoto);
                                            Gson gson = new Gson();
                                            String strphotoList = gson.toJson(photoList);
                                            LogUtils.e("strphotoList", strphotoList);
                                            initsuredata(userId2, orgId2, tcsn2, learnsn2, courseLength, photoList);
                                        } else {
                                            //无测验题无照片自动提交
                                            LoginUserBean userInfo = UserManger.getUserInfo();
                                            String userId2 = userInfo.getData().getUserId();
                                            SharedPreferences sp2 = getSharedPreferences("CourseDetailsActivity",
                                                    Context.MODE_PRIVATE);
                                            int tcsn2 = sp2.getInt("tcsn", 0);
                                            int learnsn2 = sp2.getInt("learnsn", 0);
                                            String orgId2 = sp2.getString("orgId", "");

                                            String firsttimestr2 = sp2.getString("firsttime", "");//第一次抓拍时间
                                            String imgurl1 = sp2.getString("imgurl", "");//第一次拍照图片地址获取
                                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                                            userTcPhoto.setUrl(imgurl1);
                                            userTcPhoto.setSnapTime(firsttimestr2);
                                            photoList.add(userTcPhoto);
                                            Gson gson = new Gson();
                                            String strphotoList = gson.toJson(photoList);
                                            LogUtils.e("strphotoList", strphotoList);
                                            initsuredata(userId2, orgId2, tcsn2, learnsn2, courseLength, photoList);
                                        }
                                    }
                                }
                            });
                        }
                    };
                    timer1.schedule(timerTask, 0, 1000);

                } else {
                    String[] splitformat = format.split(":");
                    String format1 = splitformat[0];
                    String format2 = splitformat[1];
                    String format3 = splitformat[2];
                    int iformat1 = Integer.valueOf(format1);//转int
                    int iformat2 = Integer.valueOf(format2);//转int
                    int iformat3 = Integer.valueOf(format3);//转int
                    int formattime = iformat1 * 3600 + iformat2 * 60 + iformat3 * 1;
                    formattimecnt = formattime;
                    timerTask = new TimerTask() {
                        @Override
                        public void run() {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    String stringTime = getStringTime(formattimecnt++);
                                    tv_cumulativeLength.setText(stringTime);
                                    LogUtils.e("format", stringTime);
                                    SharedPreferences sp1 = getSharedPreferences("CourseDetailsActivity",
                                            Context.MODE_PRIVATE);
                                    SharedPreferences.Editor edit = sp1.edit();
                                    edit.putString("format", stringTime);
                                    edit.commit();
                                    int courseLength = sp1.getInt("courseLength", 0);
                                    int courseLengthtime = courseLength * 60;
                                    String courseLengthtime1 = getStringTime(courseLengthtime);
//                                    int num = sp1.getInt("num", 0);
//                                    String[] splitformat = stringTime.split(":");
//                                    String format1 = splitformat[0];
//                                    String format2 = splitformat[1];
//                                    String format3 = splitformat[2];
//                                    int iformat1 = Integer.valueOf(format1);//转int
//                                    int iformat2 = Integer.valueOf(format2);//转int
//                                    int iformat3 = Integer.valueOf(format3);//转int
//                                    int formattime = iformat1 * 3600 + iformat2 * 60 + iformat3 * 1;
//                                    if(formattime==courseLength*60) {
//                                        timerTask.cancel();
//                                    }
                                    if (stringTime.equals(courseLengthtime1)) {
                                        timerTask.cancel();
                                        if (setYm.equals("")) {
                                            TiShiDialog.Builder builder1 = new TiShiDialog.Builder(CourseDetailsActivity.this);
                                            builder1.setMessage("仅查看,不能自动提交");
                                            builder1.setTitle("提示:");
                                            builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                                public void onClick(DialogInterface dialog, int which) {
                                                    dialog.dismiss();
                                                    ;
                                                    //设置你的操作事项

                                                }
                                            });
                                            builder1.create().show();
                                            return;
                                        }
                                        if (rowsList.size() != 0) {
                                            for (int i = 0; i < rowsList.size(); i++) {
                                                if (rowsList.get(i).isSelect() == false) {
                                                    TiShiDialog.Builder builder1 = new TiShiDialog.Builder(CourseDetailsActivity.this);
                                                    builder1.setMessage("第" + (i + 1) + "测验题未答，请答题");
                                                    builder1.setTitle("提示:");
                                                    builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                                        public void onClick(DialogInterface dialog, int which) {
                                                            dialog.dismiss();
                                                            ;
                                                            //设置你的操作事项
                                                        }
                                                    });
                                                    builder1.create().show();
                                                    return;
                                                } else {
                                                    if (rowsList.get(i).isLOOP() == false) {
                                                        TiShiDialog.Builder builder1 = new TiShiDialog.Builder(CourseDetailsActivity.this);
                                                        builder1.setMessage("第" + (i + 1) + "测验题回答错误，请重新答题");
                                                        builder1.setTitle("提示:");
                                                        builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                                            public void onClick(DialogInterface dialog, int which) {
                                                                dialog.dismiss();
                                                                ;
                                                                //设置你的操作事项
                                                            }
                                                        });
                                                        builder1.create().show();
                                                        return;
                                                    }
                                                }
                                            }
                                            //有测验题无照片自动提交
                                            LoginUserBean userInfo = UserManger.getUserInfo();
                                            String userId2 = userInfo.getData().getUserId();
                                            SharedPreferences sp2 = getSharedPreferences("CourseDetailsActivity",
                                                    Context.MODE_PRIVATE);
                                            int tcsn2 = sp2.getInt("tcsn", 0);
                                            int learnsn2 = sp2.getInt("learnsn", 0);
                                            String orgId2 = sp2.getString("orgId", "");

                                            String firsttimestr2 = sp2.getString("firsttime", "");//第一次抓拍时间
                                            String imgurl1 = sp2.getString("imgurl", "");//第一次拍照图片地址获取
                                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                                            userTcPhoto.setUrl(imgurl1);
                                            userTcPhoto.setSnapTime(firsttimestr2);
                                            photoList.add(userTcPhoto);
                                            Gson gson = new Gson();
                                            String strphotoList = gson.toJson(photoList);
                                            LogUtils.e("strphotoList", strphotoList);
                                            initsuredata(userId2, orgId2, tcsn2, learnsn2, courseLength, photoList);
                                        } else {
                                            //无测验题无照片自动提交
                                            LoginUserBean userInfo = UserManger.getUserInfo();
                                            String userId2 = userInfo.getData().getUserId();
                                            SharedPreferences sp2 = getSharedPreferences("CourseDetailsActivity",
                                                    Context.MODE_PRIVATE);
                                            int tcsn2 = sp2.getInt("tcsn", 0);
                                            int learnsn2 = sp2.getInt("learnsn", 0);
                                            String orgId2 = sp2.getString("orgId", "");

                                            String firsttimestr2 = sp2.getString("firsttime", "");//第一次抓拍时间
                                            String imgurl1 = sp2.getString("imgurl", "");//第一次拍照图片地址获取
                                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                                            userTcPhoto.setUrl(imgurl1);
                                            userTcPhoto.setSnapTime(firsttimestr2);
                                            photoList.add(userTcPhoto);
                                            Gson gson = new Gson();
                                            String strphotoList = gson.toJson(photoList);
                                            LogUtils.e("strphotoList", strphotoList);
                                            initsuredata(userId2, orgId2, tcsn2, learnsn2, courseLength, photoList);
                                        }
                                    }
                                }
                            });
                        }
                    };
                    timer1.schedule(timerTask, 0, 1000);
                }
            }
//            else if (what == 1) {
//                WebSettings settings = web.getSettings();
//                // 允许使用脚本语言
//                settings.setJavaScriptEnabled(true);
//                // 支持缩放
//                settings.setSupportZoom(true);
//
//                //  mWebView.addJavascriptInterface(new JavaScriptinterface(BannerItemAty.this), "android");
//                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
//                    settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
//                }//Android 5.0中使用webView 加载网页不显示图片问题
//                // 在当前应用加载网页(直接加载网页不经过浏览器）
//                web.setWebViewClient(new WebViewClient() {
//                    @Override // 开始加载网页时触发
//                    public void onPageStarted(WebView view, String url, Bitmap favicon) {
//                        super.onPageStarted(view, url, favicon);
//
//                    }
//
//                    @Override // 网页加载完成之后触发
//                    public void onPageFinished(WebView view, String url) {
//
//                        super.onPageFinished(view, url);
//
//                    }
//                });
//
//                SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
//                        Context.MODE_PRIVATE);
//                int tcsn = sp.getInt("tcsn", 0);
//                web.loadUrl(AppInterfaceConfig.BASE_URL + "app/course/content?" + "sn=" + tcsn);
//
//                // 显示进度
//                web.setWebChromeClient(new WebChromeClient() {
//                    @Override // 加载网页进度改变时触发
//                    public void onProgressChanged(WebView view, int newProgress) {
//
//                        super.onProgressChanged(view, newProgress);
//                    }
//                });
//            }
            else if (what == 3) {

                SharedPreferences sp1 = getSharedPreferences("CourseDetailsActivity",
                        Context.MODE_PRIVATE);
                String format = sp1.getString("format", "");
                if (format.equals("")) {
                    timerTask = new TimerTask() {
                        int cnt = 0;

                        @Override
                        public void run() {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    String stringTime = getStringTime(cnt++);
                                    tv_cumulativeLength.setText(stringTime);
                                    SharedPreferences sp1 = getSharedPreferences("CourseDetailsActivity",
                                            Context.MODE_PRIVATE);
                                    String firsttimestr1 = getStringTime(firsttime);
                                    LogUtils.e("format", stringTime);
                                    LogUtils.e("firsttime", firsttimestr1);
                                    SharedPreferences.Editor edit = sp1.edit();
                                    edit.putString("format", stringTime);
                                    edit.putString("firsttime", firsttimestr1);
                                    edit.commit();

                                    if (stringTime.equals(firsttimestr1)) {

                                        if (setYm.equals("")) {
                                            return;
                                        }
                                        timerTask.cancel();
                                        initDialog();

                                    }
                                }
                            });
                        }
                    };
                    timer1.schedule(timerTask, 0, 1000);
                } else {
                    String[] splitformat = format.split(":");
                    String format1 = splitformat[0];
                    String format2 = splitformat[1];
                    String format3 = splitformat[2];
                    int iformat1 = Integer.valueOf(format1);//转int
                    int iformat2 = Integer.valueOf(format2);//转int
                    int iformat3 = Integer.valueOf(format3);//转int
                    int formattime = iformat1 * 3600 + iformat2 * 60 + iformat3 * 1;
                    formattimecnt = formattime;
                    timerTask = new TimerTask() {
                        @Override
                        public void run() {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    int numTime = formattimecnt++;
                                    String stringTime = getStringTime(numTime);
                                    tv_cumulativeLength.setText(stringTime);
                                    SharedPreferences sp1 = getSharedPreferences("CourseDetailsActivity",
                                            Context.MODE_PRIVATE);
                                    String firsttimestr1 = getStringTime(firsttime);
                                    int numFifthpart = sp1.getInt("numFifthpart", 0);
//                                    int firsttime2 = sp1.getInt("intfirsttime2" + otcSn, 0);
                                    String numFifthpartstr = getStringTime(numFifthpart);
                                    LogUtils.e("format", stringTime);
                                    LogUtils.e("firsttime1", firsttimestr1);
                                    LogUtils.e("numFifthpartstr", numFifthpartstr);
                                    SharedPreferences.Editor edit = sp1.edit();
                                    edit.putString("format", stringTime);
                                    edit.putString("firsttime", firsttimestr1);
                                    edit.putString("numFifthpartstr", numFifthpartstr);
                                    edit.commit();
//                                    String imgurl = sp1.getString("imgurl" + otcSn+learnsn, "");
                                    if (numTime == firsttime) {
                                        if (show_camera_iv.getDrawable() == null) {
                                            if (setYm.equals("")) {
                                                return;
                                            }
                                            edit.putString("firsttime", firsttimestr1);
                                            edit.commit();
                                            timerTask.cancel();
                                            initDialog();
                                        }
                                    } else if (numTime == numFifthpart) {
                                        if (show_camera_iv1.getDrawable() == null) {
                                            if (setYm.equals("")) {
                                                return;
                                            }
                                            edit.putString("numFifthpartstr", numFifthpartstr);
                                            edit.commit();
                                            timerTask.cancel();
                                            initDialog3();
                                        }
                                    } else {
                                        LoginUserBean userInfo = UserManger.getUserInfo();
                                        String userId2 = userInfo.getData().getUserId();
                                        int courseLength = sp1.getInt("courseLength", 0);
                                        LogUtils.e("退出拍照后计时", stringTime + "/");
                                        String[] splitformat = stringTime.split(":");
                                        String format1 = splitformat[0];
                                        String format2 = splitformat[1];
                                        String format3 = splitformat[2];
                                        int iformat1 = Integer.valueOf(format1);//转int
                                        int iformat2 = Integer.valueOf(format2);//转int
                                        int iformat3 = Integer.valueOf(format3);//转int
                                        int formattime = iformat1 * 3600 + iformat2 * 60 + iformat3 * 1;
//                                        if(formattime==courseLength*60) {
//                                            timerTask.cancel();
//                                        }
                                        if (formattime == courseLength * 60) {
                                            timerTask.cancel();
                                            if (setYm.equals("")) {
                                                TiShiDialog.Builder builder1 = new TiShiDialog.Builder(CourseDetailsActivity.this);
                                                builder1.setMessage("仅查看,不能自动提交");
                                                builder1.setTitle("提示:");
                                                builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                                    public void onClick(DialogInterface dialog, int which) {
                                                        dialog.dismiss();
                                                        ;
                                                        //设置你的操作事项

                                                    }
                                                });
                                                builder1.create().show();
                                                return;
                                            }
                                            //自动提交
                                            if (rowsList.size() != 0) {

                                                for (int i = 0; i < rowsList.size(); i++) {
                                                    if (rowsList.get(i).isSelect() == false) {
                                                        TiShiDialog.Builder builder1 = new TiShiDialog.Builder(CourseDetailsActivity.this);
                                                        builder1.setMessage("第" + (i + 1) + "测验题未答，请答题");
                                                        builder1.setTitle("提示:");
                                                        builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                                            public void onClick(DialogInterface dialog, int which) {
                                                                dialog.dismiss();
                                                                //设置你的操作事项
                                                            }
                                                        });

                                                        builder1.create().show();
                                                        return;
                                                    } else {

                                                        if (rowsList.get(i).isLOOP() == false) {
                                                            TiShiDialog.Builder builder1 = new TiShiDialog.Builder(CourseDetailsActivity.this);
                                                            builder1.setMessage("第" + (i + 1) + "测验题回答错误，请重新答题");
                                                            builder1.setTitle("提示:");
                                                            builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                                                public void onClick(DialogInterface dialog, int which) {
                                                                    dialog.dismiss();
                                                                    //设置你的操作事项
                                                                }
                                                            });
                                                            builder1.create().show();

                                                            return;
                                                        }
                                                    }
                                                }


                                                //有题有照片自动提交
                                                SharedPreferences sp2 = getSharedPreferences("CourseDetailsActivity",
                                                        Context.MODE_PRIVATE);

                                                int tcsn2 = sp2.getInt("tcsn", 0);
                                                //    int sn2 = sp2.getInt("sn", 0);
                                                String orgId2 = sp2.getString("orgId", "");
                                                int learnsn2 = sp2.getInt("learnsn", 0);
                                                String firsttimestr = sp2.getString("firsttime", "");//第一次抓拍时间
                                                String numFifthpartstr1 = sp2.getString("numFifthpartstr", "");//第二次抓拍时间
                                                String imgurl1 = sp2.getString("imgurl", "");
                                                String imgurl2 = sp2.getString("imgurl1", "");
                                                String firsttimesub = firsttimestr.substring(3, 8);//截取字符串00:00:00变成00:00
                                                String numFifthpartstr1sub = numFifthpartstr1.substring(3, 8);//截取字符串00:00:00变成00:00

                                                List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                                                UserTcPhoto userTcPhoto = new UserTcPhoto();
                                                userTcPhoto.setUrl(imgurl1);
                                                userTcPhoto.setSnapTime(firsttimesub);
                                                UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                                                userTcPhoto1.setUrl(imgurl2);
                                                userTcPhoto1.setSnapTime(numFifthpartstr1sub);
                                                photoList.add(userTcPhoto);
                                                photoList.add(userTcPhoto1);
                                                Gson gson = new Gson();
                                                String strphotoList = gson.toJson(photoList);
                                                LogUtils.e("strphotoList", strphotoList);
                                                initsuredata(userId2, orgId2, tcsn2, learnsn2, courseLength, photoList);
                                            } else {//无题有照片自动提交
                                                SharedPreferences sp2 = getSharedPreferences("CourseDetailsActivity",
                                                        Context.MODE_PRIVATE);
                                                int tcsn2 = sp2.getInt("tcsn", 0);
//                                                int sn2 = sp2.getInt("sn", 0);
                                                String orgId2 = sp2.getString("orgId", "");
                                                int learnsn2 = sp2.getInt("learnsn", 0);
                                                String firsttimestr = sp2.getString("firsttime", "");//第一次抓拍时间
                                                String numFifthpartstr1 = sp2.getString("numFifthpartstr", "");//第二次抓拍时间
                                                String imgurl1 = sp2.getString("imgurl", "");
                                                String imgurl2 = sp2.getString("imgurl1", "");
                                                String firsttimesub = firsttimestr.substring(3, 8);//截取字符串00:00:00变成00:00
                                                String numFifthpartstr1sub = numFifthpartstr1.substring(3, 8);//截取字符串00:00:00变成00:00

                                                List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                                                UserTcPhoto userTcPhoto = new UserTcPhoto();
                                                userTcPhoto.setUrl(imgurl1);
                                                userTcPhoto.setSnapTime(firsttimesub);
                                                UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                                                userTcPhoto1.setUrl(imgurl2);
                                                userTcPhoto1.setSnapTime(numFifthpartstr1sub);
                                                photoList.add(userTcPhoto);
                                                photoList.add(userTcPhoto1);
                                                Gson gson = new Gson();
                                                String strphotoList = gson.toJson(photoList);
                                                LogUtils.e("strphotoList", strphotoList);
                                                initsuredata(userId2, orgId2, tcsn2, learnsn2, courseLength, photoList);
                                            }
                                        }
                                    }

                                }
                            });
                        }
                    };
                    timer1.schedule(timerTask, 0, 1000);

                }
            } else if (what == 4) {
                SharedPreferences sp1 = getSharedPreferences("CourseDetailsActivity",
                        Context.MODE_PRIVATE);
                String format = sp1.getString("format", "");
                if (format.equals("")) {
                    timerTask = new TimerTask() {
                        int cnt = 0;

                        @Override
                        public void run() {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    String stringTime = getStringTime(cnt++);
                                    tv_cumulativeLength.setText(stringTime);
                                    SharedPreferences sp1 = getSharedPreferences("CourseDetailsActivity",
                                            Context.MODE_PRIVATE);
                                    String firsttimestr1 = getStringTime(firsttime);
                                    LogUtils.e("format", stringTime);
                                    LogUtils.e("firsttime", firsttimestr1);
                                    SharedPreferences.Editor edit = sp1.edit();
                                    edit.putString("format", stringTime);
                                    edit.putString("firsttime", firsttimestr1);
                                    edit.commit();

                                    if (stringTime.equals(firsttimestr1)) {
                                        //    timerTask.cancel();
                                        if (setYm.equals("")) {
                                            return;
                                        }
                                        timerTask.cancel();
                                        initDialog();

                                    }
                                }
                            });
                        }
                    };
                    timer1.schedule(timerTask, 0, 1000);
                } else {
                    String[] splitformat = format.split(":");
                    String format1 = splitformat[0];
                    String format2 = splitformat[1];
                    String format3 = splitformat[2];
                    int iformat1 = Integer.valueOf(format1);//转int
                    int iformat2 = Integer.valueOf(format2);//转int
                    int iformat3 = Integer.valueOf(format3);//转int
                    int formattime = iformat1 * 3600 + iformat2 * 60 + iformat3 * 1;
                    formattimecnt = formattime;
                    timerTask = new TimerTask() {
                        @Override
                        public void run() {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    int numTime = formattimecnt++;
                                    String stringTime = getStringTime(numTime);
                                    tv_cumulativeLength.setText(stringTime);
                                    SharedPreferences sp1 = getSharedPreferences("CourseDetailsActivity",
                                            Context.MODE_PRIVATE);
                                    int numsecondpart = sp1.getInt("numsecondpart", 0);
                                    int numFifthpart = sp1.getInt("numFifthpart", 0);
                                    String firsttimestr1 = getStringTime(firsttime);
                                    String numsecondpartstr = getStringTime(numsecondpart);
                                    String numFifthpartstr = getStringTime(numFifthpart);
                                    LogUtils.e("format", stringTime);
                                    LogUtils.e("firsttime1", firsttimestr1);
                                    LogUtils.e("numsecondpartstr", numsecondpartstr);
                                    LogUtils.e("numFifthpartstr", numFifthpartstr);
                                    SharedPreferences.Editor edit = sp1.edit();
                                    edit.putString("format", stringTime);
                                    edit.putString("firsttime", firsttimestr1);
                                    edit.putString("numsecondpartstr", numsecondpartstr);
                                    edit.putString("numFifthpartstr", numFifthpartstr);
                                    edit.commit();
//                                    String imgurl = sp1.getString("imgurl" + otcSn+learnsn, "");
                                    if (numTime == firsttime) {

                                        if (show_camera_iv.getDrawable() == null) {

                                            if (setYm.equals("")) {
                                                return;
                                            }
                                            edit.putString("firsttime", firsttimestr1);
                                            edit.commit();
                                            timerTask.cancel();
                                            initDialog();
                                        }

                                    } else if (numTime == numsecondpart) {

                                        if (show_camera_iv1.getDrawable() == null) {
                                            if (setYm.equals("")) {
                                                return;
                                            }
                                            edit.putString("numsecondpartstr", numsecondpartstr);
                                            edit.commit();
                                            timerTask.cancel();
                                            initDialog3();
                                        }

                                    } else if (numTime == numFifthpart) {
                                        if (show_camera_iv2.getDrawable() == null) {
                                            if (setYm.equals("")) {
                                                return;
                                            }
                                            edit.putString("numFifthpartstr", numFifthpartstr);
                                            edit.commit();
                                            timerTask.cancel();
                                            initDialog4();
                                        }
                                    } else {
                                        LoginUserBean userInfo1 = UserManger.getUserInfo();
                                        String userId2 = userInfo1.getData().getUserId();
                                        int courseLength = sp1.getInt("courseLength", 0);
//                                        int num = sp1.getInt("num"+ otcSn, 0);
                                        LogUtils.e("退出拍照后计时", stringTime + "/");
                                        String[] splitformat = stringTime.split(":");
                                        String format1 = splitformat[0];
                                        String format2 = splitformat[1];
                                        String format3 = splitformat[2];
                                        int iformat1 = Integer.valueOf(format1);//转int
                                        int iformat2 = Integer.valueOf(format2);//转int
                                        int iformat3 = Integer.valueOf(format3);//转int
                                        int formattime = iformat1 * 3600 + iformat2 * 60 + iformat3 * 1;
//                                        if(formattime==courseLength*60) {
//                                            timerTask.cancel();
//                                        }
                                        if (formattime == courseLength * 60) {
                                            timerTask.cancel();
                                            if (setYm.equals("")) {
                                                TiShiDialog.Builder builder1 = new TiShiDialog.Builder(CourseDetailsActivity.this);
                                                builder1.setMessage("仅查看,不能自动提交");
                                                builder1.setTitle("提示:");
                                                builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                                    public void onClick(DialogInterface dialog, int which) {
                                                        dialog.dismiss();
                                                        ;
                                                        //设置你的操作事项

                                                    }
                                                });
                                                builder1.create().show();
                                                return;
                                            }
                                            //自动提交
                                            if (rowsList.size() != 0) {

                                                for (int i = 0; i < rowsList.size(); i++) {
                                                    if (rowsList.get(i).isSelect() == false) {
                                                        TiShiDialog.Builder builder1 = new TiShiDialog.Builder(CourseDetailsActivity.this);
                                                        builder1.setMessage("第" + (i + 1) + "测验题未答，请答题");
                                                        builder1.setTitle("提示:");
                                                        builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                                            public void onClick(DialogInterface dialog, int which) {
                                                                dialog.dismiss();
                                                                //设置你的操作事项
                                                            }
                                                        });

                                                        builder1.create().show();
                                                        return;
                                                    } else {

                                                        if (rowsList.get(i).isLOOP() == false) {
                                                            TiShiDialog.Builder builder1 = new TiShiDialog.Builder(CourseDetailsActivity.this);
                                                            builder1.setMessage("第" + (i + 1) + "测验题回答错误，请重新答题");
                                                            builder1.setTitle("提示:");
                                                            builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                                                public void onClick(DialogInterface dialog, int which) {
                                                                    dialog.dismiss();
                                                                    //设置你的操作事项
                                                                }
                                                            });
                                                            builder1.create().show();

                                                            return;
                                                        }
                                                    }
                                                }


                                                //有题有照片自动提交

                                                SharedPreferences sp2 = getSharedPreferences("CourseDetailsActivity",
                                                        Context.MODE_PRIVATE);
                                                int tcsn2 = sp2.getInt("tcsn", 0);
                                                //   int sn2 = sp2.getInt("sn", 0);
                                                String orgId2 = sp2.getString("orgId", "");
                                                //   int otcSn2 = sp2.getInt("otcSn", 0);
                                                int learnsn2 = sp2.getInt("learnsn", 0);
                                                String firsttimestr = sp2.getString("firsttime", "");//第一次抓拍时间
                                                String numsecondpartstr1 = sp2.getString("numsecondpartstr", "");//第二次抓拍时间
                                                String numFifthpartstr1 = sp2.getString("numFifthpartstr", "");//第三次抓拍时间
                                                String imgurl1 = sp2.getString("imgurl", "");
                                                String imgurl2 = sp2.getString("imgurl1", "");
                                                String imgurl3 = sp2.getString("imgurl2", "");
                                                String firsttimesub = firsttimestr.substring(3, 8);//截取字符串00:00:00变成00:00
                                                String numsecondpartstrsub = numsecondpartstr1.substring(3, 8);//截取字符串00:00:00变成00:00
                                                String numFifthpartstrsub = numFifthpartstr1.substring(3, 8);//截取字符串00:00:00变成00:00

                                                List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                                                UserTcPhoto userTcPhoto = new UserTcPhoto();
                                                userTcPhoto.setUrl(imgurl1);
                                                userTcPhoto.setSnapTime(firsttimesub);
                                                UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                                                userTcPhoto1.setUrl(imgurl2);
                                                userTcPhoto1.setSnapTime(numsecondpartstrsub);
                                                UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                                                userTcPhoto2.setUrl(imgurl3);
                                                userTcPhoto2.setSnapTime(numFifthpartstrsub);
                                                photoList.add(userTcPhoto);
                                                photoList.add(userTcPhoto1);
                                                photoList.add(userTcPhoto2);
                                                Gson gson = new Gson();
                                                String strphotoList = gson.toJson(photoList);
                                                LogUtils.e("strphotoList", strphotoList);
                                                initsuredata(userId2, orgId2, tcsn2, learnsn2, courseLength, photoList);
                                            } else {//无题有照片自动提交
                                                SharedPreferences sp2 = getSharedPreferences("CourseDetailsActivity",
                                                        Context.MODE_PRIVATE);
                                                int tcsn2 = sp2.getInt("tcsn", 0);
                                                //    int sn2 = sp2.getInt("sn", 0);
                                                String orgId2 = sp2.getString("orgId", "");
                                                //    int otcSn2 = sp2.getInt("otcSn", 0);
                                                int learnsn2 = sp2.getInt("learnsn", 0);
                                                String firsttimestr = sp2.getString("firsttime", "");//第一次抓拍时间
                                                String numsecondpartstr1 = sp2.getString("numsecondpartstr", "");//第二次抓拍时间
                                                String numFifthpartstr1 = sp2.getString("numFifthpartstr", "");//第三次抓拍时间
                                                String imgurl1 = sp2.getString("imgurl", "");
                                                String imgurl2 = sp2.getString("imgurl1", "");
                                                String imgurl3 = sp2.getString("imgurl2", "");
                                                String firsttimesub = firsttimestr.substring(3, 8);//截取字符串00:00:00变成00:00
                                                String numsecondpartstrsub = numsecondpartstr1.substring(3, 8);//截取字符串00:00:00变成00:00
                                                String numFifthpartstr1sub = numFifthpartstr1.substring(3, 8);//截取字符串00:00:00变成00:00

                                                List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                                                UserTcPhoto userTcPhoto = new UserTcPhoto();
                                                userTcPhoto.setUrl(imgurl1);
                                                userTcPhoto.setSnapTime(firsttimesub);
                                                UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                                                userTcPhoto1.setUrl(imgurl2);
                                                userTcPhoto1.setSnapTime(numsecondpartstrsub);
                                                UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                                                userTcPhoto2.setUrl(imgurl3);
                                                userTcPhoto2.setSnapTime(numFifthpartstr1sub);
                                                photoList.add(userTcPhoto);
                                                photoList.add(userTcPhoto1);
                                                photoList.add(userTcPhoto2);
                                                Gson gson = new Gson();
                                                String strphotoList = gson.toJson(photoList);
                                                LogUtils.e("strphotoList", strphotoList);
                                                initsuredata(userId2, orgId2, tcsn2, learnsn2, courseLength, photoList);
                                            }
                                        }
                                    }

                                }
                            });
                        }
                    };
                    timer1.schedule(timerTask, 0, 1000);


                }

            } else if (what == 5) {
                SharedPreferences sp1 = getSharedPreferences("CourseDetailsActivity",
                        Context.MODE_PRIVATE);
                String format = sp1.getString("format", "");
                if (format.equals("")) {
                    timerTask = new TimerTask() {
                        int cnt = 0;

                        @Override
                        public void run() {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    String stringTime = getStringTime(cnt++);
                                    tv_cumulativeLength.setText(stringTime);
                                    SharedPreferences sp1 = getSharedPreferences("CourseDetailsActivity",
                                            Context.MODE_PRIVATE);
                                    String firsttimestr1 = getStringTime(firsttime);
                                    LogUtils.e("format", stringTime);
                                    LogUtils.e("firsttime", firsttimestr1);
                                    SharedPreferences.Editor edit = sp1.edit();
                                    edit.putString("format", stringTime);
                                    edit.putString("firsttime", firsttimestr1);
                                    edit.commit();

                                    if (stringTime.equals(firsttimestr1)) {
                                        if (setYm.equals("")) {
                                            return;
                                        }
                                        timerTask.cancel();
                                        initDialog();

                                    }
                                }
                            });
                        }
                    };
                    timer1.schedule(timerTask, 0, 1000);
                } else {
                    String[] splitformat = format.split(":");
                    String format1 = splitformat[0];
                    String format2 = splitformat[1];
                    String format3 = splitformat[2];
                    int iformat1 = Integer.valueOf(format1);//转int
                    int iformat2 = Integer.valueOf(format2);//转int
                    int iformat3 = Integer.valueOf(format3);//转int
                    int formattime = iformat1 * 3600 + iformat2 * 60 + iformat3 * 1;
                    formattimecnt = formattime;
                    timerTask = new TimerTask() {
                        @Override
                        public void run() {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    int numTime = formattimecnt++;
                                    String stringTime = getStringTime(numTime);
                                    tv_cumulativeLength.setText(stringTime);
                                    SharedPreferences sp1 = getSharedPreferences("CourseDetailsActivity",
                                            Context.MODE_PRIVATE);
                                    int numsecondpart = sp1.getInt("numsecondpart", 0);
                                    int numthirdpart = sp1.getInt("numthirdpart", 0);
                                    int numFifthpart = sp1.getInt("numFifthpart", 0);
                                    String firsttimestr1 = getStringTime(firsttime);
                                    String numsecondpartstr = getStringTime(numsecondpart);
                                    String numthirdpartstr = getStringTime(numthirdpart);
                                    String numFifthpartstr = getStringTime(numFifthpart);
                                    LogUtils.e("format", stringTime);
                                    LogUtils.e("firsttime1", firsttimestr1);
                                    LogUtils.e("numsecondpartstr", numsecondpartstr);
                                    LogUtils.e("numthirdpartstr", numthirdpartstr);
                                    LogUtils.e("numFifthpartstr", numFifthpartstr);
                                    SharedPreferences.Editor edit = sp1.edit();
                                    edit.putString("format", stringTime);
                                    edit.putString("firsttime", firsttimestr1);
                                    edit.putString("numsecondpartstr", numsecondpartstr);
                                    edit.putString("numthirdpartstr", numthirdpartstr);
                                    edit.putString("numFifthpartstr", numFifthpartstr);
                                    edit.commit();
//                                    String imgurl = sp1.getString("imgurl" + otcSn+learnsn, "");
                                    if (numTime == firsttime) {

                                        if (show_camera_iv.getDrawable() == null) {
                                            if (setYm.equals("")) {
                                                return;
                                            }
                                            edit.putString("firsttime", firsttimestr1);
                                            edit.commit();
                                            timerTask.cancel();
                                            initDialog();
                                        }

                                    } else if (numTime == numsecondpart) {

                                        if (show_camera_iv1.getDrawable() == null) {
                                            if (setYm.equals("")) {
                                                return;
                                            }
                                            edit.putString("numsecondpartstr", numsecondpartstr);
                                            edit.commit();
                                            timerTask.cancel();
                                            initDialog3();
                                        }

                                    } else if (numTime == numthirdpart) {
                                        if (show_camera_iv2.getDrawable() == null) {

                                            if (setYm.equals("")) {
                                                return;
                                            }
                                            edit.putString("numthirdpartstr", numthirdpartstr);
                                            edit.commit();
                                            timerTask.cancel();
                                            initDialog4();
                                        }
                                    } else if (numTime == numFifthpart) {
                                        if (show_camera_iv3.getDrawable() == null) {
                                            if (setYm.equals("")) {
                                                return;
                                            }
                                            edit.putString("numFifthpartstr", numFifthpartstr);
                                            edit.commit();
                                            timerTask.cancel();
                                            initDialog5();
                                        }
                                    } else {
                                        LoginUserBean userInfo1 = UserManger.getUserInfo();
                                        String userId2 = userInfo1.getData().getUserId();
                                        int courseLength = sp1.getInt("courseLength", 0);
                                        LogUtils.e("退出拍照后计时", stringTime + "/");
                                        String[] splitformat = stringTime.split(":");
                                        String format1 = splitformat[0];
                                        String format2 = splitformat[1];
                                        String format3 = splitformat[2];
                                        int iformat1 = Integer.valueOf(format1);//转int
                                        int iformat2 = Integer.valueOf(format2);//转int
                                        int iformat3 = Integer.valueOf(format3);//转int
                                        int formattime = iformat1 * 3600 + iformat2 * 60 + iformat3 * 1;
//                                        if(formattime==courseLength*60) {
//                                            timerTask.cancel();
//                                        }
                                        if (formattime == courseLength * 60) {
                                            timerTask.cancel();
                                            if (setYm.equals("")) {
                                                TiShiDialog.Builder builder1 = new TiShiDialog.Builder(CourseDetailsActivity.this);
                                                builder1.setMessage("仅查看,不能自动提交");
                                                builder1.setTitle("提示:");
                                                builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                                    public void onClick(DialogInterface dialog, int which) {
                                                        dialog.dismiss();
                                                        ;
                                                        //设置你的操作事项

                                                    }
                                                });
                                                builder1.create().show();
                                                return;
                                            }
                                            //自动提交
                                            if (rowsList.size() != 0) {

                                                for (int i = 0; i < rowsList.size(); i++) {
                                                    if (rowsList.get(i).isSelect() == false) {
                                                        TiShiDialog.Builder builder1 = new TiShiDialog.Builder(CourseDetailsActivity.this);
                                                        builder1.setMessage("第" + (i + 1) + "测验题未答，请答题");
                                                        builder1.setTitle("提示:");
                                                        builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                                            public void onClick(DialogInterface dialog, int which) {
                                                                dialog.dismiss();
                                                                //设置你的操作事项
                                                            }
                                                        });

                                                        builder1.create().show();
                                                        return;
                                                    } else {

                                                        if (rowsList.get(i).isLOOP() == false) {
                                                            TiShiDialog.Builder builder1 = new TiShiDialog.Builder(CourseDetailsActivity.this);
                                                            builder1.setMessage("第" + (i + 1) + "测验题回答错误，请重新答题");
                                                            builder1.setTitle("提示:");
                                                            builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                                                public void onClick(DialogInterface dialog, int which) {
                                                                    dialog.dismiss();
                                                                    //设置你的操作事项
                                                                }
                                                            });
                                                            builder1.create().show();

                                                            return;
                                                        }
                                                    }
                                                }


                                                //有题有照片自动提交
                                                SharedPreferences sp2 = getSharedPreferences("CourseDetailsActivity",
                                                        Context.MODE_PRIVATE);
                                                int tcsn2 = sp2.getInt("tcsn", 0);
//                                                int sn2 = sp2.getInt("sn", 0);
                                                String orgId2 = sp2.getString("orgId", "");
                                                int learnsn2 = sp2.getInt("learnsn", 0);
                                                String firsttimestr = sp2.getString("firsttime", "");//第一次抓拍时间
                                                String numsecondpartstr1 = sp2.getString("numsecondpartstr", "");//第二次抓拍时间
                                                String numthirdpartstr1 = sp2.getString("numthirdpartstr", "");//第三次抓拍时间
                                                String numFifthpartstr1 = sp2.getString("numFifthpartstr", "");//第四次抓拍时间
                                                String imgurl1 = sp2.getString("imgurl", "");
                                                String imgurl2 = sp2.getString("imgurl1", "");
                                                String imgurl3 = sp2.getString("imgurl2", "");
                                                String imgurl4 = sp2.getString("imgurl3", "");
                                                String firsttimesub = firsttimestr.substring(3, 8);//截取字符串00:00:00变成00:00
                                                String numsecondpartstrsub = numsecondpartstr1.substring(3, 8);//截取字符串00:00:00变成00:00
                                                String numthirdpartstrsub = numthirdpartstr1.substring(3, 8);//截取字符串00:00:00变成00:00
                                                String numFifthpartstrsub = numFifthpartstr1.substring(3, 8);//截取字符串00:00:00变成00:00

                                                List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                                                UserTcPhoto userTcPhoto = new UserTcPhoto();
                                                userTcPhoto.setUrl(imgurl1);
                                                userTcPhoto.setSnapTime(firsttimesub);
                                                UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                                                userTcPhoto1.setUrl(imgurl2);
                                                userTcPhoto1.setSnapTime(numsecondpartstrsub);
                                                UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                                                userTcPhoto2.setUrl(imgurl3);
                                                userTcPhoto2.setSnapTime(numthirdpartstrsub);
                                                UserTcPhoto userTcPhoto3 = new UserTcPhoto();
                                                userTcPhoto3.setUrl(imgurl4);
                                                userTcPhoto3.setSnapTime(numFifthpartstrsub);
                                                photoList.add(userTcPhoto);
                                                photoList.add(userTcPhoto1);
                                                photoList.add(userTcPhoto2);
                                                photoList.add(userTcPhoto3);
                                                Gson gson = new Gson();
                                                String strphotoList = gson.toJson(photoList);
                                                LogUtils.e("strphotoList", strphotoList);
                                                initsuredata(userId2, orgId2, tcsn2, learnsn2, courseLength, photoList);
                                            } else {//无题有照片自动提交
                                                SharedPreferences sp2 = getSharedPreferences("CourseDetailsActivity",
                                                        Context.MODE_PRIVATE);
                                                int tcsn2 = sp2.getInt("tcsn", 0);
                                                String orgId2 = sp2.getString("orgId", "");
                                                int learnsn2 = sp2.getInt("learnsn", 0);
                                                String firsttimestr = sp2.getString("firsttime", "");//第一次抓拍时间
                                                String numsecondpartstr1 = sp2.getString("numsecondpartstr", "");//第二次抓拍时间
                                                String numthirdpartstr1 = sp2.getString("numthirdpartstr", "");//第三次抓拍时间
                                                String numFifthpartstr1 = sp2.getString("numFifthpartstr", "");//第四次抓拍时间
                                                String imgurl1 = sp2.getString("imgurl", "");
                                                String imgurl2 = sp2.getString("imgurl1", "");
                                                String imgurl3 = sp2.getString("imgurl2", "");
                                                String imgurl4 = sp2.getString("imgurl3", "");
                                                String firsttimesub = firsttimestr.substring(3, 8);//截取字符串00:00:00变成00:00
                                                String numsecondpartstrsub = numsecondpartstr1.substring(3, 8);//截取字符串00:00:00变成00:00
                                                String numthirdpartstrsub = numthirdpartstr1.substring(3, 8);//截取字符串00:00:00变成00:00
                                                String numFifthpartstrsub = numFifthpartstr1.substring(3, 8);//截取字符串00:00:00变成00:00

                                                List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                                                UserTcPhoto userTcPhoto = new UserTcPhoto();
                                                userTcPhoto.setUrl(imgurl1);
                                                userTcPhoto.setSnapTime(firsttimesub);
                                                UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                                                userTcPhoto1.setUrl(imgurl2);
                                                userTcPhoto1.setSnapTime(numsecondpartstrsub);
                                                UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                                                userTcPhoto2.setUrl(imgurl3);
                                                userTcPhoto2.setSnapTime(numthirdpartstrsub);
                                                UserTcPhoto userTcPhoto3 = new UserTcPhoto();
                                                userTcPhoto3.setUrl(imgurl4);
                                                userTcPhoto3.setSnapTime(numFifthpartstrsub);
                                                photoList.add(userTcPhoto);
                                                photoList.add(userTcPhoto1);
                                                photoList.add(userTcPhoto2);
                                                photoList.add(userTcPhoto3);
                                                Gson gson = new Gson();
                                                String strphotoList = gson.toJson(photoList);
                                                LogUtils.e("strphotoList", strphotoList);
                                                initsuredata(userId2, orgId2, tcsn2, learnsn2, courseLength, photoList);
                                            }
                                        }
                                    }

                                }
                            });
                        }
                    };
                    timer1.schedule(timerTask, 0, 1000);


                }
            } else if (what == 6) {
                SharedPreferences sp1 = getSharedPreferences("CourseDetailsActivity",
                        Context.MODE_PRIVATE);
                String format = sp1.getString("format", "");
                if (format.equals("")) {
                    timerTask = new TimerTask() {
                        int cnt = 0;

                        @Override
                        public void run() {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    String stringTime = getStringTime(cnt++);
                                    tv_cumulativeLength.setText(stringTime);
                                    SharedPreferences sp1 = getSharedPreferences("CourseDetailsActivity",
                                            Context.MODE_PRIVATE);
                                    String firsttimestr1 = getStringTime(firsttime);
                                    LogUtils.e("format", stringTime);
                                    LogUtils.e("firsttime", firsttimestr1);
                                    SharedPreferences.Editor edit = sp1.edit();
                                    edit.putString("format", stringTime);
                                    edit.putString("firsttime", firsttimestr1);
                                    edit.commit();

                                    if (stringTime.equals(firsttimestr1)) {
                                        if (setYm.equals("")) {
                                            return;
                                        }
                                        timerTask.cancel();
                                        initDialog();

                                    }
                                }
                            });
                        }
                    };
                    timer1.schedule(timerTask, 0, 1000);
                } else {
                    String[] splitformat = format.split(":");
                    String format1 = splitformat[0];
                    String format2 = splitformat[1];
                    String format3 = splitformat[2];
                    int iformat1 = Integer.valueOf(format1);//转int
                    int iformat2 = Integer.valueOf(format2);//转int
                    int iformat3 = Integer.valueOf(format3);//转int
                    int formattime = iformat1 * 3600 + iformat2 * 60 + iformat3 * 1;
                    formattimecnt = formattime;
                    timerTask = new TimerTask() {
                        @Override
                        public void run() {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    int numTime = formattimecnt++;
                                    String stringTime = getStringTime(numTime);
                                    tv_cumulativeLength.setText(stringTime);
                                    SharedPreferences sp1 = getSharedPreferences("CourseDetailsActivity",
                                            Context.MODE_PRIVATE);
                                    int numsecondpart = sp1.getInt("numsecondpart", 0);
                                    int numthirdpart = sp1.getInt("numthirdpart", 0);
                                    int numfourpart = sp1.getInt("numfourpart", 0);
                                    int numFifthpart = sp1.getInt("numFifthpart", 0);
                                    String firsttimestr1 = getStringTime(firsttime);
                                    String numsecondpartstr = getStringTime(numsecondpart);
                                    String numthirdpartstr = getStringTime(numthirdpart);
                                    String numfourpartstr = getStringTime(numfourpart);
                                    String numFifthpartstr = getStringTime(numFifthpart);
                                    LogUtils.e("format", stringTime);
                                    LogUtils.e("firsttime1", firsttimestr1);
                                    LogUtils.e("numsecondpartstr", numsecondpartstr);
                                    LogUtils.e("numthirdpartstr", numthirdpartstr);
                                    LogUtils.e("numfourpartstr", numfourpartstr);
                                    LogUtils.e("numFifthpartstr", numFifthpartstr);
                                    SharedPreferences.Editor edit = sp1.edit();
                                    edit.putString("format", stringTime);
                                    edit.putString("firsttime", firsttimestr1);
                                    edit.putString("numsecondpartstr", numsecondpartstr);
                                    edit.putString("numthirdpartstr", numthirdpartstr);
                                    edit.putString("numfourpartstr", numfourpartstr);
                                    edit.putString("numFifthpartstr", numFifthpartstr);
                                    edit.commit();
                                    if (numTime == firsttime) {

                                        if (show_camera_iv.getDrawable() == null) {
                                            if (setYm.equals("")) {
                                                return;
                                            }
                                            edit.putString("firsttime", firsttimestr1);
                                            edit.commit();
                                            timerTask.cancel();
                                            initDialog();
                                        }

                                    } else if (numTime == numsecondpart) {

                                        if (show_camera_iv1.getDrawable() == null) {
                                            if (setYm.equals("")) {
                                                return;
                                            }
                                            edit.putString("numsecondpartstr", numsecondpartstr);
                                            edit.commit();
                                            timerTask.cancel();
                                            initDialog3();
                                        }

                                    } else if (numTime == numthirdpart) {

                                        if (show_camera_iv2.getDrawable() == null) {
                                            if (setYm.equals("")) {
                                                return;
                                            }
                                            edit.putString("numthirdpartstr", numthirdpartstr);
                                            edit.commit();
                                            timerTask.cancel();
                                            initDialog4();
                                        }

                                    } else if (numTime == numfourpart) {

                                        if (show_camera_iv3.getDrawable() == null) {
                                            if (setYm.equals("")) {
                                                return;
                                            }
                                            edit.putString("numfourpartstr", numfourpartstr);
                                            edit.commit();
                                            timerTask.cancel();
                                            initDialog5();
                                        }

                                    } else if (numTime == numFifthpart) {
                                        if (show_camera_iv4.getDrawable() == null) {
                                            if (setYm.equals("")) {
                                                return;
                                            }
                                            edit.putString("numFifthpartstr", numFifthpartstr);
                                            edit.commit();
                                            timerTask.cancel();
                                            initDialog6();
                                        }
                                    } else {
                                        LoginUserBean userInfo1 = UserManger.getUserInfo();
                                        String userId2 = userInfo1.getData().getUserId();
                                        int courseLength = sp1.getInt("courseLength", 0);
                                        LogUtils.e("退出拍照后计时", stringTime + "/");
                                        String[] splitformat = stringTime.split(":");
                                        String format1 = splitformat[0];
                                        String format2 = splitformat[1];
                                        String format3 = splitformat[2];
                                        int iformat1 = Integer.valueOf(format1);//转int
                                        int iformat2 = Integer.valueOf(format2);//转int
                                        int iformat3 = Integer.valueOf(format3);//转int
                                        int formattime = iformat1 * 3600 + iformat2 * 60 + iformat3 * 1;
//                                        if(formattime==courseLength*60) {
//                                            timerTask.cancel();
//                                        }
                                        if (formattime == courseLength * 60) {
                                            timerTask.cancel();
                                            if (setYm.equals("")) {
                                                TiShiDialog.Builder builder1 = new TiShiDialog.Builder(CourseDetailsActivity.this);
                                                builder1.setMessage("仅查看,不能自动提交");
                                                builder1.setTitle("提示:");
                                                builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                                    public void onClick(DialogInterface dialog, int which) {
                                                        dialog.dismiss();
                                                        ;
                                                        //设置你的操作事项

                                                    }
                                                });
                                                builder1.create().show();
                                                return;
                                            }
                                            //自动提交
                                            if (rowsList.size() != 0) {

                                                for (int i = 0; i < rowsList.size(); i++) {
                                                    if (rowsList.get(i).isSelect() == false) {
                                                        TiShiDialog.Builder builder1 = new TiShiDialog.Builder(CourseDetailsActivity.this);
                                                        builder1.setMessage("第" + (i + 1) + "测验题未答，请答题");
                                                        builder1.setTitle("提示:");
                                                        builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                                            public void onClick(DialogInterface dialog, int which) {
                                                                dialog.dismiss();
                                                                //设置你的操作事项
                                                            }
                                                        });

                                                        builder1.create().show();
                                                        return;
                                                    } else {

                                                        if (rowsList.get(i).isLOOP() == false) {
                                                            TiShiDialog.Builder builder1 = new TiShiDialog.Builder(CourseDetailsActivity.this);
                                                            builder1.setMessage("第" + (i + 1) + "测验题回答错误，请重新答题");
                                                            builder1.setTitle("提示:");
                                                            builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                                                public void onClick(DialogInterface dialog, int which) {
                                                                    dialog.dismiss();
                                                                    //设置你的操作事项
                                                                }
                                                            });
                                                            builder1.create().show();

                                                            return;
                                                        }
                                                    }
                                                }


                                                //有题有照片自动提交

                                                SharedPreferences sp2 = getSharedPreferences("CourseDetailsActivity",
                                                        Context.MODE_PRIVATE);
                                                int tcsn2 = sp2.getInt("tcsn", 0);
                                                String orgId2 = sp2.getString("orgId", "");
                                                int learnsn2 = sp2.getInt("learnsn", 0);
                                                String firsttimestr = sp2.getString("firsttime", "");//第一次抓拍时间
                                                String numsecondpartstr1 = sp2.getString("numsecondpartstr", "");//第二次抓拍时间
                                                String numthirdpartstr1 = sp2.getString("numthirdpartstr", "");//第三次抓拍时间
                                                String numfourpartstr1 = sp2.getString("numfourpartstr", "");//第四次抓拍时间
                                                String numFifthpartstr1 = sp2.getString("numFifthpartstr", "");//第五次抓拍时间
                                                String imgurl1 = sp2.getString("imgurl", "");
                                                String imgurl2 = sp2.getString("imgurl1", "");
                                                String imgurl3 = sp2.getString("imgurl2", "");
                                                String imgurl4 = sp2.getString("imgurl3", "");
                                                String imgurl5 = sp2.getString("imgurl4", "");
                                                String firsttimesub = firsttimestr.substring(3, 8);//截取字符串00:00:00变成00:00
                                                String numsecondpartstrsub = numsecondpartstr1.substring(3, 8);//截取字符串00:00:00变成00:00
                                                String numthirdpartstrsub = numthirdpartstr1.substring(3, 8);//截取字符串00:00:00变成00:00
                                                String numfourpartstrsub = numfourpartstr1.substring(3, 8);//截取字符串00:00:00变成00:00
                                                String numFifthpartstrsub = numFifthpartstr1.substring(3, 8);//截取字符串00:00:00变成00:00

                                                List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                                                UserTcPhoto userTcPhoto = new UserTcPhoto();
                                                userTcPhoto.setUrl(imgurl1);
                                                userTcPhoto.setSnapTime(firsttimesub);
                                                UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                                                userTcPhoto1.setUrl(imgurl2);
                                                userTcPhoto1.setSnapTime(numsecondpartstrsub);
                                                UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                                                userTcPhoto2.setUrl(imgurl3);
                                                userTcPhoto2.setSnapTime(numthirdpartstrsub);
                                                UserTcPhoto userTcPhoto3 = new UserTcPhoto();
                                                userTcPhoto3.setUrl(imgurl4);
                                                userTcPhoto3.setSnapTime(numfourpartstrsub);
                                                UserTcPhoto userTcPhoto4 = new UserTcPhoto();
                                                userTcPhoto4.setUrl(imgurl5);
                                                userTcPhoto4.setSnapTime(numFifthpartstrsub);
                                                photoList.add(userTcPhoto);
                                                photoList.add(userTcPhoto1);
                                                photoList.add(userTcPhoto2);
                                                photoList.add(userTcPhoto3);
                                                photoList.add(userTcPhoto4);
                                                Gson gson = new Gson();
                                                String strphotoList = gson.toJson(photoList);
                                                LogUtils.e("strphotoList", strphotoList);
                                                initsuredata(userId2, orgId2, tcsn2, learnsn2, courseLength, photoList);
                                            } else {//无题有照片自动提交

                                                SharedPreferences sp2 = getSharedPreferences("CourseDetailsActivity",
                                                        Context.MODE_PRIVATE);
                                                int tcsn2 = sp2.getInt("tcsn", 0);
                                                String orgId2 = sp2.getString("orgId", "");
                                                int learnsn2 = sp2.getInt("learnsn", 0);
                                                String firsttimestr = sp2.getString("firsttime", "");//第一次抓拍时间
                                                String numsecondpartstr1 = sp2.getString("numsecondpartstr", "");//第二次抓拍时间
                                                String numthirdpartstr1 = sp2.getString("numthirdpartstr", "");//第三次抓拍时间
                                                String numfourpartstr1 = sp2.getString("numfourpartstr", "");//第四次抓拍时间
                                                String numFifthpartstr1 = sp2.getString("numFifthpartstr", "");//第五次抓拍时间
                                                String imgurl1 = sp2.getString("imgurl", "");
                                                String imgurl2 = sp2.getString("imgurl1", "");
                                                String imgurl3 = sp2.getString("imgurl2", "");
                                                String imgurl4 = sp2.getString("imgurl3", "");
                                                String imgurl5 = sp2.getString("imgurl4", "");
                                                String firsttimesub = firsttimestr.substring(3, 8);//截取字符串00:00:00变成00:00
                                                String numsecondpartstrsub = numsecondpartstr1.substring(3, 8);//截取字符串00:00:00变成00:00
                                                String numthirdpartstrsub = numthirdpartstr1.substring(3, 8);//截取字符串00:00:00变成00:00
                                                String numfourpartstrsub = numfourpartstr1.substring(3, 8);//截取字符串00:00:00变成00:00
                                                String numFifthpartstrsub = numFifthpartstr1.substring(3, 8);//截取字符串00:00:00变成00:00

                                                List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                                                UserTcPhoto userTcPhoto = new UserTcPhoto();
                                                userTcPhoto.setUrl(imgurl1);
                                                userTcPhoto.setSnapTime(firsttimesub);
                                                UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                                                userTcPhoto1.setUrl(imgurl2);
                                                userTcPhoto1.setSnapTime(numsecondpartstrsub);
                                                UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                                                userTcPhoto2.setUrl(imgurl3);
                                                userTcPhoto2.setSnapTime(numthirdpartstrsub);
                                                UserTcPhoto userTcPhoto3 = new UserTcPhoto();
                                                userTcPhoto3.setUrl(imgurl4);
                                                userTcPhoto3.setSnapTime(numfourpartstrsub);
                                                UserTcPhoto userTcPhoto4 = new UserTcPhoto();
                                                userTcPhoto4.setUrl(imgurl5);
                                                userTcPhoto4.setSnapTime(numFifthpartstrsub);
                                                photoList.add(userTcPhoto);
                                                photoList.add(userTcPhoto1);
                                                photoList.add(userTcPhoto2);
                                                photoList.add(userTcPhoto3);
                                                photoList.add(userTcPhoto4);
                                                Gson gson = new Gson();
                                                String strphotoList = gson.toJson(photoList);
                                                LogUtils.e("strphotoList", strphotoList);
                                                initsuredata(userId2, orgId2, tcsn2, learnsn2, courseLength, photoList);
                                            }
                                        }
                                    }

                                }
                            });
                        }
                    };
                    timer1.schedule(timerTask, 0, 1000);


                }
            }
        }
    };
    private Camera mCamera;
    private SurfaceHolder mHolder;
    private PopupWindow mPopWindow;
    private long rangeTime;
    private FileInputStream fStream;
    private List<CourseDetailSubjectBean.RowsBean> rowsList;
    //   private int readInterval;

    private boolean isloob = true;
    private Timer timer1;
    private int minPer;
    private int firsttime;
    private int subformatTurnSecond;
    private SensorManager sensorManager;
    private Jzvd.JZAutoFullscreenListener sensorEventListener;
    private PopupWindow mSorryPopWindow;
    private TextView downtime;
    private String setYm;
    private ProgressDialog mProgressDialog;
    private int photoMark;
    private int signMark;
    private PopupWindow mStopPopWindow;
    private int firsttime1;
    private PopupWindow mPopWindow2;
    private boolean ishave = false;
    private TextView tv_photo2;
    private TextView tv_photo4;
    private TextView tv_photo1;
    private TextView tv_photo;
    private ImageView img_photo;


    SuperFileView2 mSuperFileView;
    private JumpingBeans jumpingBeans2;
    private PopupWindow mDownloadPopWindow;
    private CourseDetailRvSubjectApt courseDetailSubjectApt;

    @Override
    public int getLayoutId() {
        return R.layout.activity_course_details;
    }

    private String getStringTime(int cnt) {
        int hour = cnt / 3600;
        int min = cnt % 3600 / 60;
        int second = cnt % 60;
        return String.format(Locale.CHINA, "%02d:%02d:%02d", hour, min, second);
    }


    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.img_playorpause) {
            toggle();
        } else if (id == R.id.tv_course12) {//中途保存

            if (setYm.equals("")) {

                TiShiDialog.Builder builder1 = new TiShiDialog.Builder(CourseDetailsActivity.this);
                builder1.setMessage("仅查看,不能保存记录");
                builder1.setTitle("提示:");
                builder1.setPositiveButton("确认退出", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        ;
                        SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                                Context.MODE_PRIVATE);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.clear();
                        edit.commit();
//                        LoginUserBean userInfo = UserManger.getUserInfo();
//                        String userId = userInfo.getData().getUserId();
//                        SharedPreferences sp = getSharedPreferences("durationandformat1" + userId,
//                                Context.MODE_PRIVATE);
//                        int otcSn = sp.getInt("otcSn", 0);
//                        int learnsn = sp.getInt("learnsn", 0);
//                        String format = sp.getString("format"+ otcSn+learnsn, "");
//                        String imgurl = sp.getString("imgurl"+ otcSn+learnsn, "");
//                        int tcsn = sp.getInt("tcsn", 0);
//                        int sn = sp.getInt("sn", 0);
//                        String statYm = sp.getString("statYm", "");
//                        String orgId = sp.getString("orgId", "");
//                        String[] splitformat = format.split(":");
//                        String format1 = splitformat[0];
//                        String format2 = splitformat[1];
//                        String format3 = splitformat[2];
//                        int iformat1 = Integer.valueOf(format1);//转int
//                        int iformat2 = Integer.valueOf(format2);//转int
//                        int iformat3 = Integer.valueOf(format3);//转int
//                        int formattime = iformat1 * 3600 + iformat2 * 60 + iformat3 * 1;
//                        int photoMark = sp.getInt("photoMark", 0);
//                        if(photoMark==1)
//                        {
//                            int readLength = (formattime%60==0)?formattime/60:(formattime/60+1);//累计学习时间
//                            LogUtils.e("readLength",readLength+"");
//                            String firsttime = sp.getString("firsttime"+ otcSn, "");//第一次抓拍时间
//                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
//                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
//                            //                     String durationsub = duration.substring(3, 8);//截取字符串00:00:00变成00:00
//                            UserTcPhoto userTcPhoto = new UserTcPhoto();
//                            userTcPhoto.setSnapTime(firsttimesub);
//                            userTcPhoto.setUrl(imgurl);
//                            photoList.add(userTcPhoto);
//                            Gson gson = new Gson();
//                            String strphotoList = gson.toJson(photoList);
//                            LogUtils.e("strphotoList",strphotoList);
//                            initsavedata(sn,userId,orgId,tcsn,otcSn,learnsn,readLength,photoList);
//                        }else if(photoMark==0){
//                            int readLength = (formattime%60==0)?formattime/60:(formattime/60+1);//累计学习时间
//                            LogUtils.e("readLength",readLength+"");
//                            String firsttime = sp.getString("firsttime"+ otcSn, "");//第一次抓拍时间
//                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
//                            //      String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
//                            //                     String durationsub = duration.substring(3, 8);//截取字符串00:00:00变成00:00
//                            UserTcPhoto userTcPhoto = new UserTcPhoto();
//                            userTcPhoto.setSnapTime(firsttime);
//                            userTcPhoto.setUrl(imgurl);
//                            photoList.add(userTcPhoto);
//                            Gson gson = new Gson();
//                            String strphotoList = gson.toJson(photoList);
//                            LogUtils.e("strphotoList",strphotoList);
//                            initsavedata(sn,userId,orgId,tcsn,otcSn,learnsn,readLength,photoList);
//                        }
                        timerTask.cancel();
                        timer1.cancel();
                        timerTask = null;
                        timer1 = null;
                        finish();

                    }
                });

                builder1.setNegativeButton("继续学习",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                //     initStopDialog();
                                dialog.dismiss();
                            }
                        });
                builder1.create().show();
                return;
            }
            SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                    Context.MODE_PRIVATE);

            String formats1 = sp.getString("format", "");
            int courseLength1 = sp.getInt("courseLength", 0);
            String[] splitformat1 = formats1.split(":");
            String formatstr1 = splitformat1[0];
            String formatstr2 = splitformat1[1];
            String formatstr3 = splitformat1[2];
            int iformat4 = Integer.valueOf(formatstr1);//转int
            int iformat5 = Integer.valueOf(formatstr2);//转int
            int iformat6 = Integer.valueOf(formatstr3);//转int
            int formattime1 = iformat4 * 3600 + iformat5 * 60 + iformat6 * 1;
            if (formattime1 < 60) {
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                View view1 = View.inflate(CourseDetailsActivity.this, R.layout.diolog_learn_layout, null);
                TextView tv_message = (TextView) view1.findViewById(R.id.message);//输入内容
                tv_message.setText("您本次学习未满一分钟，无法保存学习进度，退出后将重新学习本课程。");
                TextView btn_sure = (TextView) view1.findViewById(R.id.positiveButton);
                TextView btn_cancel = (TextView) view1.findViewById(R.id.negativeButton);
                btn_sure.setText("确认退出");
                btn_cancel.setText("继续学习");
                final AlertDialog dialog = builder.create();
                dialog.show();
                dialog.getWindow().setContentView(view1);
                dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                dialog.setCancelable(false);
                btn_sure.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        dialog.dismiss();

                        SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                                Context.MODE_PRIVATE);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.clear();
                        edit.commit();
//                        LoginUserBean userInfo = UserManger.getUserInfo();
//                        String userId = userInfo.getData().getUserId();
//                        SharedPreferences sp = getSharedPreferences("durationandformat1" + userId,
//                                Context.MODE_PRIVATE);
//                        int otcSn = sp.getInt("otcSn", 0);
//                        int learnsn = sp.getInt("learnsn", 0);
//                        String format = sp.getString("format"+ otcSn+learnsn, "");
//                        String imgurl = sp.getString("imgurl"+ otcSn+learnsn, "");
//                        int tcsn = sp.getInt("tcsn", 0);
//                        int sn = sp.getInt("sn", 0);
//                        String statYm = sp.getString("statYm", "");
//                        String orgId = sp.getString("orgId", "");
//                        String[] splitformat = format.split(":");
//                        String format1 = splitformat[0];
//                        String format2 = splitformat[1];
//                        String format3 = splitformat[2];
//                        int iformat1 = Integer.valueOf(format1);//转int
//                        int iformat2 = Integer.valueOf(format2);//转int
//                        int iformat3 = Integer.valueOf(format3);//转int
//                        int formattime = iformat1 * 3600 + iformat2 * 60 + iformat3 * 1;
//                        int photoMark = sp.getInt("photoMark", 0);
//                        if(photoMark==1)
//                        {
//                            int readLength = (formattime%60==0)?formattime/60:(formattime/60+1);//累计学习时间
//                            LogUtils.e("readLength",readLength+"");
//                            String firsttime = sp.getString("firsttime"+ otcSn, "");//第一次抓拍时间
//                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
//                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
//                            //                     String durationsub = duration.substring(3, 8);//截取字符串00:00:00变成00:00
//                            UserTcPhoto userTcPhoto = new UserTcPhoto();
//                            userTcPhoto.setSnapTime(firsttimesub);
//                            userTcPhoto.setUrl(imgurl);
//                            photoList.add(userTcPhoto);
//                            Gson gson = new Gson();
//                            String strphotoList = gson.toJson(photoList);
//                            LogUtils.e("strphotoList",strphotoList);
//                            initsavedata(sn,userId,orgId,tcsn,otcSn,learnsn,readLength,photoList);
//                        }else if(photoMark==0){
//                            int readLength = (formattime%60==0)?formattime/60:(formattime/60+1);//累计学习时间
//                            LogUtils.e("readLength",readLength+"");
//                            String firsttime = sp.getString("firsttime"+ otcSn, "");//第一次抓拍时间
//                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
//                            //      String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
//                            //                     String durationsub = duration.substring(3, 8);//截取字符串00:00:00变成00:00
//                            UserTcPhoto userTcPhoto = new UserTcPhoto();
//                            userTcPhoto.setSnapTime(firsttime);
//                            userTcPhoto.setUrl(imgurl);
//                            photoList.add(userTcPhoto);
//                            Gson gson = new Gson();
//                            String strphotoList = gson.toJson(photoList);
//                            LogUtils.e("strphotoList",strphotoList);
//                            initsavedata(sn,userId,orgId,tcsn,otcSn,learnsn,readLength,photoList);
//                        }
                        timerTask.cancel();
                        timer1.cancel();
                        timerTask = null;
                        timer1 = null;
                        finish();
                        //设置你的操作事项
                    }
                });

                btn_cancel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {


//                                LoginUserBean userInfo = UserManger.getUserInfo();
//                                String userId = userInfo.getData().getUserId();
//                                SharedPreferences sp = getSharedPreferences("durationandformat1"+userId,
//                                        Context.MODE_PRIVATE);
//                                int photoMark = sp.getInt("photoMark", 0);
//                                if(photoMark==1)
//                                {
//                                    Thread thread = new Thread(new Runnable() {
//                                        @Override
//                                        public void run() {
//                                            //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
//                                            mHandler.sendEmptyMessage(0);
//                                        }
//                                    });
//                                    thread.start();
//                                }else if(photoMark==0){
//                                    Thread thread = new Thread(new Runnable() {
//                                        @Override
//                                        public void run() {
//                                            //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
//                                            mHandler.sendEmptyMessage(2);
//                                        }
//                                    });
//                                    thread.start();
//                                }
                        //      tv_pause.setText("继续学习");
//                            LoginUserBean userInfo = UserManger.getUserInfo();
//                            String userId = userInfo.getData().getUserId();
//                            SharedPreferences sp = getSharedPreferences("durationandformat1" + userId,
//                                    Context.MODE_PRIVATE);
//                            int photoMark = sp.getInt("photoMark", 0);
//                            if (photoMark == 1) {
//                                Thread thread = new Thread(new Runnable() {
//                                    @Override
//                                    public void run() {
//                                        //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
//                                        mHandler.sendEmptyMessage(0);
//                                    }
//                                });
//                                thread.start();
//                            } else if (photoMark == 0) {
//                                Thread thread = new Thread(new Runnable() {
//                                    @Override
//                                    public void run() {
//                                        //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
//                                        mHandler.sendEmptyMessage(2);
//                                    }
//                                });
//                                thread.start();
//                            }
                        dialog.dismiss();
                    }
                });

            } else {
                if (formattime1 == courseLength1 * 60)//课程达到课程时长点保存相当于提交
                {
                    if (rowsList.size() != 0) {

                        for (int i = 0; i < rowsList.size(); i++) {
                            if (rowsList.get(i).isSelect() == false) {
                                TiShiDialog.Builder builder1 = new TiShiDialog.Builder(this);
                                builder1.setMessage("第" + (i + 1) + "测验题未答，请答题");
                                builder1.setTitle("提示:");
                                builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.dismiss();
                                        ;
                                        //设置你的操作事项
                                    }
                                });
                                builder1.create().show();

                                return;
                            } else {

                                if (rowsList.get(i).isLOOP() == false) {
                                    TiShiDialog.Builder builder1 = new TiShiDialog.Builder(this);
                                    builder1.setMessage("第" + (i + 1) + "测验题回答错误，请重新答题");
                                    builder1.setTitle("提示:");
                                    builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog, int which) {
                                            dialog.dismiss();
                                            ;
                                            //设置你的操作事项
                                        }
                                    });
                                    builder1.create().show();


                                    return;
                                }
                            }
                        }
                        //有题目接口
                        int tcsn = sp.getInt("tcsn", 0);
                        int learnsn = sp.getInt("learnsn", 0);
                        String orgId = sp.getString("orgId", "");
                        if (photoMark == 1) {
                            LoginUserBean userInfo = UserManger.getUserInfo();
                            String userId = userInfo.getData().getUserId();//useid
                            String firsttime = sp.getString("firsttime", "");//第一次抓拍时间
                            String imgurl = sp.getString("imgurl", "");//第一次拍照图片地址获取
                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                            userTcPhoto.setUrl(imgurl);
                            userTcPhoto.setSnapTime(firsttimesub);
                            photoList.add(userTcPhoto);
                            Gson gson = new Gson();
                            String strphotoList = gson.toJson(photoList);
                            LogUtils.e("strphotoList", strphotoList);
                            mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                            mProgressDialog.setMessage("提交中...");
                            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                            mProgressDialog.setCancelable(false);
                            mProgressDialog.show();
                            new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength1, 1, photoList, this, 3);
                        } else if (photoMark == 0) {
                            LoginUserBean userInfo = UserManger.getUserInfo();
                            String userId = userInfo.getData().getUserId();//useid
                            String firsttime = sp.getString("firsttime", "");//第一次抓拍时间
                            String imgurl = sp.getString("imgurl", "");//第一次拍照图片地址获取
                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                            userTcPhoto.setUrl(imgurl);
                            userTcPhoto.setSnapTime(firsttime);
                            photoList.add(userTcPhoto);
                            Gson gson = new Gson();
                            String strphotoList = gson.toJson(photoList);
                            LogUtils.e("strphotoList", strphotoList);
                            mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                            mProgressDialog.setMessage("提交中...");
                            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                            mProgressDialog.setCancelable(false);
                            mProgressDialog.show();
                            new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength1, 1, photoList, this, 3);
                        } else if (photoMark == 2) {
                            LoginUserBean userInfo = UserManger.getUserInfo();
                            String userId = userInfo.getData().getUserId();//useid
                            String imgurl = sp.getString("imgurl", "");
                            String imgurl1 = sp.getString("imgurl1", "");
                            String firsttime = sp.getString("firsttime", "");//第一次抓拍时间
                            String numFifthpartstr = sp.getString("numFifthpartstr", "");//第二次抓拍时间
                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                            userTcPhoto.setUrl(imgurl);
                            userTcPhoto.setSnapTime(firsttimesub);
                            UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                            userTcPhoto1.setUrl(imgurl1);
                            userTcPhoto1.setSnapTime(numFifthpartstr1);
                            photoList.add(userTcPhoto);
                            photoList.add(userTcPhoto1);
                            Gson gson = new Gson();
                            String strphotoList = gson.toJson(photoList);
                            LogUtils.e("strphotoList", strphotoList);
                            mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                            mProgressDialog.setMessage("提交中...");
                            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                            mProgressDialog.setCancelable(false);
                            mProgressDialog.show();
                            new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength1, 1, photoList, this, 3);
                        } else if (photoMark == 3) {
                            LoginUserBean userInfo = UserManger.getUserInfo();
                            String userId = userInfo.getData().getUserId();//useid
                            String imgurl1 = sp.getString("imgurl", "");
                            String firsttime = sp.getString("firsttime", "");//第一次抓拍时间
                            String imgurl2 = sp.getString("imgurl1", "");
                            String numsecondpartstr = sp.getString("numsecondpartstr", "");//第二次抓拍时间
                            String imgurl3 = sp.getString("imgurl2", "");
                            String numFifthpartstr = sp.getString("numFifthpartstr", "");//第三次抓拍时间
                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                            userTcPhoto.setUrl(imgurl1);
                            userTcPhoto.setSnapTime(firsttimesub);
                            UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                            userTcPhoto1.setUrl(imgurl2);
                            userTcPhoto1.setSnapTime(numsecondpartstr1);
                            UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                            userTcPhoto2.setUrl(imgurl3);
                            userTcPhoto2.setSnapTime(numFifthpartstr1);
                            photoList.add(userTcPhoto);
                            photoList.add(userTcPhoto1);
                            photoList.add(userTcPhoto2);
                            Gson gson = new Gson();
                            String strphotoList = gson.toJson(photoList);
                            LogUtils.e("strphotoList", strphotoList);
                            mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                            mProgressDialog.setMessage("提交中...");
                            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                            mProgressDialog.setCancelable(false);
                            mProgressDialog.show();
                            new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength1, 1, photoList, this, 3);
                        } else if (photoMark == 4) {
                            LoginUserBean userInfo = UserManger.getUserInfo();
                            String userId = userInfo.getData().getUserId();//useid
                            String imgurl = sp.getString("imgurl", "");
                            String imgurl1 = sp.getString("imgurl1", "");
                            String imgurl2 = sp.getString("imgurl2", "");
                            String imgurl3 = sp.getString("imgurl3", "");
                            String firsttime = sp.getString("firsttime", "");//第一次抓拍时间
                            String numsecondpartstr = sp.getString("numsecondpartstr", "");//第二次抓拍时间
                            String numthirdpartstr = sp.getString("numthirdpartstr", "");//第三次抓拍时间
                            String numFifthpartstr = sp.getString("numFifthpartstr", "");//第四次抓拍时间
                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numthirdpartstr1 = numthirdpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                            userTcPhoto.setUrl(imgurl);
                            userTcPhoto.setSnapTime(firsttimesub);
                            UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                            userTcPhoto1.setUrl(imgurl1);
                            userTcPhoto1.setSnapTime(numsecondpartstr1);
                            UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                            userTcPhoto2.setUrl(imgurl2);
                            userTcPhoto2.setSnapTime(numthirdpartstr1);
                            UserTcPhoto userTcPhoto3 = new UserTcPhoto();
                            userTcPhoto3.setUrl(imgurl3);
                            userTcPhoto3.setSnapTime(numFifthpartstr1);
                            photoList.add(userTcPhoto);
                            photoList.add(userTcPhoto1);
                            photoList.add(userTcPhoto2);
                            photoList.add(userTcPhoto3);
                            Gson gson = new Gson();
                            String strphotoList = gson.toJson(photoList);
                            LogUtils.e("strphotoList", strphotoList);
                            mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                            mProgressDialog.setMessage("提交中...");
                            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                            mProgressDialog.setCancelable(false);
                            mProgressDialog.show();
                            new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength1, 1, photoList, this, 3);
                        } else if (photoMark == 5) {
                            LoginUserBean userInfo = UserManger.getUserInfo();
                            String userId = userInfo.getData().getUserId();//useid
                            String imgurl = sp.getString("imgurl", "");
                            String imgurl1 = sp.getString("imgurl1", "");
                            String imgurl2 = sp.getString("imgurl2", "");
                            String imgurl3 = sp.getString("imgurl3", "");
                            String imgurl4 = sp.getString("imgurl4", "");
                            String firsttime = sp.getString("firsttime", "");//第一次抓拍时间
                            String numsecondpartstr = sp.getString("numsecondpartstr", "");//第二次抓拍时间
                            String numthirdpartstr = sp.getString("numthirdpartstr", "");//第三次抓拍时间
                            String numfourpartstr = sp.getString("numfourpartstr", "");//第四次抓拍时间
                            String numFifthpartstr = sp.getString("numFifthpartstr", "");//第五次抓拍时间
                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numthirdpartstr1 = numthirdpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numfourpartstr1 = numfourpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                            userTcPhoto.setUrl(imgurl);
                            userTcPhoto.setSnapTime(firsttimesub);
                            UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                            userTcPhoto1.setUrl(imgurl1);
                            userTcPhoto1.setSnapTime(numsecondpartstr1);
                            UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                            userTcPhoto2.setUrl(imgurl2);
                            userTcPhoto2.setSnapTime(numthirdpartstr1);
                            UserTcPhoto userTcPhoto3 = new UserTcPhoto();
                            userTcPhoto3.setUrl(imgurl3);
                            userTcPhoto3.setSnapTime(numfourpartstr1);
                            UserTcPhoto userTcPhoto4 = new UserTcPhoto();
                            userTcPhoto4.setUrl(imgurl4);
                            userTcPhoto4.setSnapTime(numFifthpartstr1);
                            photoList.add(userTcPhoto);
                            photoList.add(userTcPhoto1);
                            photoList.add(userTcPhoto2);
                            photoList.add(userTcPhoto3);
                            photoList.add(userTcPhoto4);
                            Gson gson = new Gson();
                            String strphotoList = gson.toJson(photoList);
                            LogUtils.e("strphotoList", strphotoList);
                            mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                            mProgressDialog.setMessage("提交中...");
                            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                            mProgressDialog.setCancelable(false);
                            mProgressDialog.show();
                            new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength1, 1, photoList, this, 3);
                        }
                    } else {//无题目有照片接口
                        int tcsn = sp.getInt("tcsn", 0);
                        int learnsn = sp.getInt("learnsn", 0);
                        String orgId = sp.getString("orgId", "");
                        if (photoMark == 1) {
                            LoginUserBean userInfo = UserManger.getUserInfo();
                            String userId = userInfo.getData().getUserId();//useid
                            String firsttime = sp.getString("firsttime", "");//第一次抓拍时间
                            String imgurl = sp.getString("imgurl", "");//第一次拍照图片地址获取
                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                            userTcPhoto.setUrl(imgurl);
                            userTcPhoto.setSnapTime(firsttimesub);
                            photoList.add(userTcPhoto);
                            Gson gson = new Gson();
                            String strphotoList = gson.toJson(photoList);
                            LogUtils.e("strphotoList", strphotoList);
                            mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                            mProgressDialog.setMessage("提交中...");
                            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                            mProgressDialog.setCancelable(false);
                            mProgressDialog.show();
                            new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength1, 1, photoList, this, 3);
                        } else if (photoMark == 0) {
                            LoginUserBean userInfo = UserManger.getUserInfo();
                            String userId = userInfo.getData().getUserId();//useid
                            String firsttime = sp.getString("firsttime", "");//第一次抓拍时间
                            String imgurl = sp.getString("imgurl", "");//第一次拍照图片地址获取
                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                            userTcPhoto.setUrl(imgurl);
                            userTcPhoto.setSnapTime(firsttime);
                            photoList.add(userTcPhoto);
                            Gson gson = new Gson();
                            String strphotoList = gson.toJson(photoList);
                            LogUtils.e("strphotoList", strphotoList);
                            mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                            mProgressDialog.setMessage("提交中...");
                            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                            mProgressDialog.setCancelable(false);
                            mProgressDialog.show();
                            new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength1, 1, photoList, this, 3);
                        } else if (photoMark == 2) {
                            LoginUserBean userInfo = UserManger.getUserInfo();
                            String userId = userInfo.getData().getUserId();//useid
                            String imgurl = sp.getString("imgurl", "");
                            String imgurl1 = sp.getString("imgurl1", "");
                            String firsttime = sp.getString("firsttime", "");//第一次抓拍时间
                            String numFifthpartstr = sp.getString("numFifthpartstr", "");//第二次抓拍时间
                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                            userTcPhoto.setUrl(imgurl);
                            userTcPhoto.setSnapTime(firsttimesub);
                            UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                            userTcPhoto1.setUrl(imgurl1);
                            userTcPhoto1.setSnapTime(numFifthpartstr1);
                            photoList.add(userTcPhoto);
                            photoList.add(userTcPhoto1);
                            Gson gson = new Gson();
                            String strphotoList = gson.toJson(photoList);
                            LogUtils.e("strphotoList", strphotoList);
                            mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                            mProgressDialog.setMessage("提交中...");
                            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                            mProgressDialog.setCancelable(false);
                            mProgressDialog.show();
                            new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength1, 1, photoList, this, 3);
                        } else if (photoMark == 3) {
                            LoginUserBean userInfo = UserManger.getUserInfo();
                            String userId = userInfo.getData().getUserId();//useid
                            String imgurl1 = sp.getString("imgurl", "");
                            String firsttime = sp.getString("firsttime", "");//第一次抓拍时间
                            String imgurl2 = sp.getString("imgurl1", "");
                            String numsecondpartstr = sp.getString("numsecondpartstr", "");//第二次抓拍时间
                            String imgurl3 = sp.getString("imgurl2", "");
                            String numFifthpartstr = sp.getString("numFifthpartstr", "");//第三次抓拍时间
                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                            userTcPhoto.setUrl(imgurl1);
                            userTcPhoto.setSnapTime(firsttimesub);
                            UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                            userTcPhoto1.setUrl(imgurl2);
                            userTcPhoto1.setSnapTime(numsecondpartstr1);
                            UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                            userTcPhoto2.setUrl(imgurl3);
                            userTcPhoto2.setSnapTime(numFifthpartstr1);
                            photoList.add(userTcPhoto);
                            photoList.add(userTcPhoto1);
                            photoList.add(userTcPhoto2);
                            Gson gson = new Gson();
                            String strphotoList = gson.toJson(photoList);
                            LogUtils.e("strphotoList", strphotoList);
                            mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                            mProgressDialog.setMessage("提交中...");
                            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                            mProgressDialog.setCancelable(false);
                            mProgressDialog.show();
                            new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength1, 1, photoList, this, 3);
                        } else if (photoMark == 4) {
                            LoginUserBean userInfo = UserManger.getUserInfo();
                            String userId = userInfo.getData().getUserId();//useid
                            String imgurl = sp.getString("imgurl", "");
                            String imgurl1 = sp.getString("imgurl1", "");
                            String imgurl2 = sp.getString("imgurl2", "");
                            String imgurl3 = sp.getString("imgurl3", "");
                            String firsttime = sp.getString("firsttime", "");//第一次抓拍时间
                            String numsecondpartstr = sp.getString("numsecondpartstr", "");//第二次抓拍时间
                            String numthirdpartstr = sp.getString("numthirdpartstr", "");//第三次抓拍时间
                            String numFifthpartstr = sp.getString("numFifthpartstr", "");//第四次抓拍时间
                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numthirdpartstr1 = numthirdpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                            userTcPhoto.setUrl(imgurl);
                            userTcPhoto.setSnapTime(firsttimesub);
                            UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                            userTcPhoto1.setUrl(imgurl1);
                            userTcPhoto1.setSnapTime(numsecondpartstr1);
                            UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                            userTcPhoto2.setUrl(imgurl2);
                            userTcPhoto2.setSnapTime(numthirdpartstr1);
                            UserTcPhoto userTcPhoto3 = new UserTcPhoto();
                            userTcPhoto3.setUrl(imgurl3);
                            userTcPhoto3.setSnapTime(numFifthpartstr1);
                            photoList.add(userTcPhoto);
                            photoList.add(userTcPhoto1);
                            photoList.add(userTcPhoto2);
                            photoList.add(userTcPhoto3);
                            Gson gson = new Gson();
                            String strphotoList = gson.toJson(photoList);
                            LogUtils.e("strphotoList", strphotoList);
                            mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                            mProgressDialog.setMessage("提交中...");
                            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                            mProgressDialog.setCancelable(false);
                            mProgressDialog.show();
                            new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength1, 1, photoList, this, 3);
                        } else if (photoMark == 5) {
                            LoginUserBean userInfo = UserManger.getUserInfo();
                            String userId = userInfo.getData().getUserId();//useid
                            String imgurl = sp.getString("imgurl", "");
                            String imgurl1 = sp.getString("imgurl1", "");
                            String imgurl2 = sp.getString("imgurl2", "");
                            String imgurl3 = sp.getString("imgurl3", "");
                            String imgurl4 = sp.getString("imgurl4", "");
                            String firsttime = sp.getString("firsttime", "");//第一次抓拍时间
                            String numsecondpartstr = sp.getString("numsecondpartstr", "");//第二次抓拍时间
                            String numthirdpartstr = sp.getString("numthirdpartstr", "");//第三次抓拍时间
                            String numfourpartstr = sp.getString("numfourpartstr", "");//第四次抓拍时间
                            String numFifthpartstr = sp.getString("numFifthpartstr", "");//第五次抓拍时间
                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numthirdpartstr1 = numthirdpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numfourpartstr1 = numfourpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                            userTcPhoto.setUrl(imgurl);
                            userTcPhoto.setSnapTime(firsttimesub);
                            UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                            userTcPhoto1.setUrl(imgurl1);
                            userTcPhoto1.setSnapTime(numsecondpartstr1);
                            UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                            userTcPhoto2.setUrl(imgurl2);
                            userTcPhoto2.setSnapTime(numthirdpartstr1);
                            UserTcPhoto userTcPhoto3 = new UserTcPhoto();
                            userTcPhoto3.setUrl(imgurl3);
                            userTcPhoto3.setSnapTime(numfourpartstr1);
                            UserTcPhoto userTcPhoto4 = new UserTcPhoto();
                            userTcPhoto4.setUrl(imgurl4);
                            userTcPhoto4.setSnapTime(numFifthpartstr1);
                            photoList.add(userTcPhoto);
                            photoList.add(userTcPhoto1);
                            photoList.add(userTcPhoto2);
                            photoList.add(userTcPhoto3);
                            photoList.add(userTcPhoto4);
                            Gson gson = new Gson();
                            String strphotoList = gson.toJson(photoList);
                            LogUtils.e("strphotoList", strphotoList);
                            mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                            mProgressDialog.setMessage("提交中...");
                            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                            mProgressDialog.setCancelable(false);
                            mProgressDialog.show();
                            new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength1, 1, photoList, this, 3);
                        }
                    }
                } else if (formattime1 < courseLength1 * 60) {//滿一分鐘保存

                    AlertDialog.Builder builder = new AlertDialog.Builder(this);
                    View view1 = View.inflate(CourseDetailsActivity.this, R.layout.diolog_learn_layout, null);
                    TextView tv_message = (TextView) view1.findViewById(R.id.message);//输入内容
                    tv_message.setText("您的学习进度已保存，下次进入将继续本课程的学习。");
                    TextView btn_sure = (TextView) view1.findViewById(R.id.positiveButton);
                    TextView btn_cancel = (TextView) view1.findViewById(R.id.negativeButton);
                    btn_sure.setText("确认退出");
                    btn_cancel.setText("继续学习");
                    final AlertDialog dialog = builder.create();
                    dialog.show();
                    dialog.getWindow().setContentView(view1);
                    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                    dialog.setCancelable(false);
                    btn_sure.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            dialog.dismiss();
                            LoginUserBean userInfo = UserManger.getUserInfo();
                            String userId1 = userInfo.getData().getUserId();
                            SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                                    Context.MODE_PRIVATE);
                            String formats1 = sp.getString("format", "");
                            String[] splitformat1 = formats1.split(":");
                            String formatstr1 = splitformat1[0];
                            String formatstr2 = splitformat1[1];
                            String formatstr3 = splitformat1[2];
                            int iformat4 = Integer.valueOf(formatstr1);//转int
                            int iformat5 = Integer.valueOf(formatstr2);//转int
                            int iformat6 = Integer.valueOf(formatstr3);//转int
                            int formattime1 = iformat4 * 3600 + iformat5 * 60 + iformat6 * 1;
                            int tcsn1 = sp.getInt("tcsn", 0);
                            int learnsn1 = sp.getInt("learnsn", 0);
                            //  int sn1 = sp.getInt("sn", 0);
                            String orgId1 = sp.getString("orgId", "");
                            //    int readLength = (formattime1 % 60 != 0) ? formattime1 / 60+1 : (formattime1 / 60);//累计学习时间
                            int readLength = (formattime1 % 60 == 0) ? formattime1 / 60 : (formattime1 / 60);//累计学习时间
                            if (photoMark == 1) {
                                String imgurl1 = sp.getString("imgurl", "");
                                //  int readLength = (formattime1 % 60 == 0) ? formattime1 / 60 : (formattime1 / 60);//累计学习时间
                                LogUtils.e("readLength", readLength + "");
                                String firsttime = sp.getString("firsttime", "");//第一次抓拍时间
                                List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                                String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                                //                     String durationsub = duration.substring(3, 8);//截取字符串00:00:00变成00:00
                                UserTcPhoto userTcPhoto = new UserTcPhoto();
                                userTcPhoto.setSnapTime(firsttimesub);
                                userTcPhoto.setUrl(imgurl1);
                                photoList.add(userTcPhoto);
                                Gson gson = new Gson();
                                String strphotoList = gson.toJson(photoList);
                                LogUtils.e("strphotoList", strphotoList);
                                initsavedata(userId1, orgId1, tcsn1, learnsn1, readLength, photoList);
                            } else if (photoMark == 0) {
                                String imgurl1 = sp.getString("imgurl", "");
                                //    int readLength = (formattime1 % 60 == 0) ? formattime1 / 60 : (formattime1 / 60);//累计学习时间
                                LogUtils.e("readLength", readLength + "");
                                String firsttime = sp.getString("firsttime", "");//第一次抓拍时间
                                List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                                //      String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                                //                     String durationsub = duration.substring(3, 8);//截取字符串00:00:00变成00:00
                                UserTcPhoto userTcPhoto = new UserTcPhoto();
                                userTcPhoto.setSnapTime(firsttime);
                                userTcPhoto.setUrl(imgurl1);
                                photoList.add(userTcPhoto);
                                Gson gson = new Gson();
                                String strphotoList = gson.toJson(photoList);
                                LogUtils.e("strphotoList", strphotoList);
                                initsavedata(userId1, orgId1, tcsn1, learnsn1, readLength, photoList);
                            } else if (photoMark == 2) {
                                //    int readLength = (formattime1 % 60 == 0) ? formattime1 / 60 : (formattime1 / 60);//累计学习时间
                                LogUtils.e("readLength", readLength + "");
                                String imgurl1 = sp.getString("imgurl", "");
                                String firsttime = sp.getString("firsttime", "");//第一次抓拍时间
                                String imgurl2 = sp.getString("imgurl1", "");
                                String numFifthpartstr = sp.getString("numFifthpartstr", "");//第二次抓拍时间
                                List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                                String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00

                                UserTcPhoto userTcPhoto = new UserTcPhoto();
                                userTcPhoto.setSnapTime(firsttimesub);
                                userTcPhoto.setUrl(imgurl1);
                                photoList.add(userTcPhoto);
                                UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                                if (imgurl2.equals("")) {
                                    userTcPhoto1.setSnapTime(numFifthpartstr);
                                    userTcPhoto1.setUrl(imgurl2);

                                } else {
                                    String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                                    userTcPhoto1.setSnapTime(numFifthpartstr1);
                                    userTcPhoto1.setUrl(imgurl2);
                                }
                                photoList.add(userTcPhoto1);
                                Gson gson = new Gson();
                                String strphotoList = gson.toJson(photoList);
                                LogUtils.e("strphotoList", strphotoList);
                                initsavedata(userId1, orgId1, tcsn1, learnsn1, readLength, photoList);
                            } else if (photoMark == 3) {
                                //   int readLength = (formattime1 % 60 == 0) ? formattime1 / 60 : (formattime1 / 60);//累计学习时间
                                LogUtils.e("readLength", readLength + "");
                                String imgurl1 = sp.getString("imgurl", "");
                                String firsttime = sp.getString("firsttime", "");//第一次抓拍时间
                                String imgurl2 = sp.getString("imgurl1", "");
                                String numsecondpartstr = sp.getString("numsecondpartstr", "");//第二次抓拍时间
                                String imgurl3 = sp.getString("imgurl2", "");
                                String numFifthpartstr = sp.getString("numFifthpartstr", "");//第三次抓拍时间
                                List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                                String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00

                                UserTcPhoto userTcPhoto = new UserTcPhoto();
                                userTcPhoto.setSnapTime(firsttimesub);
                                userTcPhoto.setUrl(imgurl1);
                                photoList.add(userTcPhoto);
                                UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                                if (imgurl2.equals("")) {
                                    userTcPhoto1.setSnapTime(numsecondpartstr);
                                    userTcPhoto1.setUrl(imgurl2);

                                } else {
                                    String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                                    userTcPhoto1.setSnapTime(numsecondpartstr1);
                                    userTcPhoto1.setUrl(imgurl2);
                                }
                                photoList.add(userTcPhoto1);
                                UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                                if (imgurl3.equals("")) {
                                    userTcPhoto2.setSnapTime(numFifthpartstr);
                                    userTcPhoto2.setUrl(imgurl3);

                                } else {
                                    String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                                    userTcPhoto2.setSnapTime(numFifthpartstr1);
                                    userTcPhoto2.setUrl(imgurl3);
                                }
                                photoList.add(userTcPhoto2);

                                Gson gson = new Gson();
                                String strphotoList = gson.toJson(photoList);
                                LogUtils.e("strphotoList", strphotoList);
                                initsavedata(userId1, orgId1, tcsn1, learnsn1, readLength, photoList);
                            } else if (photoMark == 4) {
                                //    int readLength = (formattime1 % 60 == 0) ? formattime1 / 60 : (formattime1 / 60);//累计学习时间
                                LogUtils.e("readLength", readLength + "");
                                String imgurl1 = sp.getString("imgurl", "");
                                String firsttime = sp.getString("firsttime", "");//第一次抓拍时间
                                String imgurl2 = sp.getString("imgurl1", "");
                                String numsecondpartstr = sp.getString("numsecondpartstr", "");//第二次抓拍时间
                                String imgurl3 = sp.getString("imgurl2", "");
                                String numthirdpartstr = sp.getString("numthirdpartstr", "");//第三次抓拍时间
                                String imgurl4 = sp.getString("imgurl3", "");
                                String numFifthpartstr = sp.getString("numFifthpartstr", "");//第四次抓拍时间
                                List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                                String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00

                                UserTcPhoto userTcPhoto = new UserTcPhoto();
                                userTcPhoto.setSnapTime(firsttimesub);
                                userTcPhoto.setUrl(imgurl1);
                                photoList.add(userTcPhoto);
                                UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                                if (imgurl2.equals("")) {
                                    userTcPhoto1.setSnapTime(numsecondpartstr);
                                    userTcPhoto1.setUrl(imgurl2);

                                } else {
                                    String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                                    userTcPhoto1.setSnapTime(numsecondpartstr1);
                                    userTcPhoto1.setUrl(imgurl2);
                                }
                                photoList.add(userTcPhoto1);
                                UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                                if (imgurl3.equals("")) {
                                    userTcPhoto2.setSnapTime(numthirdpartstr);
                                    userTcPhoto2.setUrl(imgurl3);

                                } else {
                                    String numthirdpartstr1 = numthirdpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                                    userTcPhoto2.setSnapTime(numthirdpartstr1);
                                    userTcPhoto2.setUrl(imgurl3);
                                }
                                photoList.add(userTcPhoto2);
                                UserTcPhoto userTcPhoto3 = new UserTcPhoto();
                                if (imgurl4.equals("")) {
                                    userTcPhoto3.setSnapTime(numFifthpartstr);
                                    userTcPhoto3.setUrl(imgurl4);

                                } else {
                                    String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                                    userTcPhoto3.setSnapTime(numFifthpartstr1);
                                    userTcPhoto3.setUrl(imgurl4);
                                }
                                photoList.add(userTcPhoto3);

                                Gson gson = new Gson();
                                String strphotoList = gson.toJson(photoList);
                                LogUtils.e("strphotoList", strphotoList);
                                initsavedata(userId1, orgId1, tcsn1, learnsn1, readLength, photoList);
                            } else if (photoMark == 5) {
                                //    int readLength = (formattime1 % 60 == 0) ? formattime1 / 60 : (formattime1 / 60);//累计学习时间
                                LogUtils.e("readLength", readLength + "");
                                String imgurl1 = sp.getString("imgurl", "");
                                String firsttime = sp.getString("firsttime", "");//第一次抓拍时间
                                String imgurl2 = sp.getString("imgurl1", "");
                                String numsecondpartstr = sp.getString("numsecondpartstr", "");//第二次抓拍时间
                                String imgurl3 = sp.getString("imgurl2", "");
                                String numthirdpartstr = sp.getString("numthirdpartstr", "");//第三次抓拍时间
                                String imgurl4 = sp.getString("imgurl3", "");
                                String numfourpartstr = sp.getString("numfourpartstr", "");//第四次抓拍时间
                                String imgurl5 = sp.getString("imgurl4", "");
                                String numFifthpartstr = sp.getString("numFifthpartstr", "");//第五次抓拍时间
                                List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                                String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00

                                UserTcPhoto userTcPhoto = new UserTcPhoto();
                                userTcPhoto.setSnapTime(firsttimesub);
                                userTcPhoto.setUrl(imgurl1);
                                photoList.add(userTcPhoto);
                                UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                                if (imgurl2.equals("")) {
                                    userTcPhoto1.setSnapTime(numsecondpartstr);
                                    userTcPhoto1.setUrl(imgurl2);

                                } else {
                                    String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                                    userTcPhoto1.setSnapTime(numsecondpartstr1);
                                    userTcPhoto1.setUrl(imgurl2);
                                }
                                photoList.add(userTcPhoto1);
                                UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                                if (imgurl3.equals("")) {
                                    userTcPhoto2.setSnapTime(numthirdpartstr);
                                    userTcPhoto2.setUrl(imgurl3);

                                } else {
                                    String numthirdpartstr1 = numthirdpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                                    userTcPhoto2.setSnapTime(numthirdpartstr1);
                                    userTcPhoto2.setUrl(imgurl3);
                                }
                                photoList.add(userTcPhoto2);
                                UserTcPhoto userTcPhoto3 = new UserTcPhoto();
                                if (imgurl4.equals("")) {
                                    userTcPhoto3.setSnapTime(numfourpartstr);
                                    userTcPhoto3.setUrl(imgurl4);

                                } else {
                                    String numfourpartstr1 = numfourpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                                    userTcPhoto3.setSnapTime(numfourpartstr1);
                                    userTcPhoto3.setUrl(imgurl4);
                                }
                                photoList.add(userTcPhoto3);
                                UserTcPhoto userTcPhoto4 = new UserTcPhoto();
                                if (imgurl5.equals("")) {
                                    userTcPhoto4.setSnapTime(numFifthpartstr);
                                    userTcPhoto4.setUrl(imgurl5);

                                } else {
                                    String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                                    userTcPhoto4.setSnapTime(numFifthpartstr1);
                                    userTcPhoto4.setUrl(imgurl5);
                                }
                                photoList.add(userTcPhoto4);
                                Gson gson = new Gson();
                                String strphotoList = gson.toJson(photoList);
                                LogUtils.e("strphotoList", strphotoList);
                                initsavedata(userId1, orgId1, tcsn1, learnsn1, readLength, photoList);
                            }
                            //设置你的操作事项
                        }
                    });

                    btn_cancel.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {


//                                LoginUserBean userInfo = UserManger.getUserInfo();
//                                String userId = userInfo.getData().getUserId();
//                                SharedPreferences sp = getSharedPreferences("durationandformat1"+userId,
//                                        Context.MODE_PRIVATE);
//                                int photoMark = sp.getInt("photoMark", 0);
//                                if(photoMark==1)
//                                {
//                                    Thread thread = new Thread(new Runnable() {
//                                        @Override
//                                        public void run() {
//                                            //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
//                                            mHandler.sendEmptyMessage(0);
//                                        }
//                                    });
//                                    thread.start();
//                                }else if(photoMark==0){
//                                    Thread thread = new Thread(new Runnable() {
//                                        @Override
//                                        public void run() {
//                                            //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
//                                            mHandler.sendEmptyMessage(2);
//                                        }
//                                    });
//                                    thread.start();
//                                }
                            //      tv_pause.setText("继续学习");
//                            LoginUserBean userInfo = UserManger.getUserInfo();
//                            String userId = userInfo.getData().getUserId();
//                            SharedPreferences sp = getSharedPreferences("durationandformat1" + userId,
//                                    Context.MODE_PRIVATE);
//                            int photoMark = sp.getInt("photoMark", 0);
//                            if (photoMark == 1) {
//                                Thread thread = new Thread(new Runnable() {
//                                    @Override
//                                    public void run() {
//                                        //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
//                                        mHandler.sendEmptyMessage(0);
//                                    }
//                                });
//                                thread.start();
//                            } else if (photoMark == 0) {
//                                Thread thread = new Thread(new Runnable() {
//                                    @Override
//                                    public void run() {
//                                        //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
//                                        mHandler.sendEmptyMessage(2);
//                                    }
//                                });
//                                thread.start();
//                            }
                            dialog.dismiss();
                        }
                    });

                }
            }
        } else if (id == R.id.img_Courseback) {
            if (setYm.equals("")) {

                TiShiDialog.Builder builder1 = new TiShiDialog.Builder(CourseDetailsActivity.this);
                builder1.setMessage("仅查看,不能保存记录");
                builder1.setTitle("提示:");
                builder1.setPositiveButton("确定退出", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        ;
                        SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                                Context.MODE_PRIVATE);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.clear();
                        edit.commit();
//                        LoginUserBean userInfo = UserManger.getUserInfo();
//                        String userId = userInfo.getData().getUserId();
//                        SharedPreferences sp = getSharedPreferences("durationandformat1" + userId,
//                                Context.MODE_PRIVATE);
//                        int otcSn = sp.getInt("otcSn", 0);
//                        int learnsn = sp.getInt("learnsn", 0);
//                        String format = sp.getString("format"+ otcSn+learnsn, "");
//                        String imgurl = sp.getString("imgurl"+ otcSn+learnsn, "");
//                        int tcsn = sp.getInt("tcsn", 0);
//                        int sn = sp.getInt("sn", 0);
//                        String statYm = sp.getString("statYm", "");
//                        String orgId = sp.getString("orgId", "");
//                        String[] splitformat = format.split(":");
//                        String format1 = splitformat[0];
//                        String format2 = splitformat[1];
//                        String format3 = splitformat[2];
//                        int iformat1 = Integer.valueOf(format1);//转int
//                        int iformat2 = Integer.valueOf(format2);//转int
//                        int iformat3 = Integer.valueOf(format3);//转int
//                        int formattime = iformat1 * 3600 + iformat2 * 60 + iformat3 * 1;
//                        int photoMark = sp.getInt("photoMark", 0);
//                        if(photoMark==1)
//                        {
//                            int readLength = (formattime%60==0)?formattime/60:(formattime/60+1);//累计学习时间
//                            LogUtils.e("readLength",readLength+"");
//                            String firsttime = sp.getString("firsttime"+ otcSn, "");//第一次抓拍时间
//                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
//                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
//                            //                     String durationsub = duration.substring(3, 8);//截取字符串00:00:00变成00:00
//                            UserTcPhoto userTcPhoto = new UserTcPhoto();
//                            userTcPhoto.setSnapTime(firsttimesub);
//                            userTcPhoto.setUrl(imgurl);
//                            photoList.add(userTcPhoto);
//                            Gson gson = new Gson();
//                            String strphotoList = gson.toJson(photoList);
//                            LogUtils.e("strphotoList",strphotoList);
//                            initsavedata(sn,userId,orgId,tcsn,otcSn,learnsn,readLength,photoList);
//                        }else if(photoMark==0){
//                            int readLength = (formattime%60==0)?formattime/60:(formattime/60+1);//累计学习时间
//                            LogUtils.e("readLength",readLength+"");
//                            String firsttime = sp.getString("firsttime"+ otcSn, "");//第一次抓拍时间
//                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
//                            //      String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
//                            //                     String durationsub = duration.substring(3, 8);//截取字符串00:00:00变成00:00
//                            UserTcPhoto userTcPhoto = new UserTcPhoto();
//                            userTcPhoto.setSnapTime(firsttime);
//                            userTcPhoto.setUrl(imgurl);
//                            photoList.add(userTcPhoto);
//                            Gson gson = new Gson();
//                            String strphotoList = gson.toJson(photoList);
//                            LogUtils.e("strphotoList",strphotoList);
//                            initsavedata(sn,userId,orgId,tcsn,otcSn,learnsn,readLength,photoList);
//                        }
                        timerTask.cancel();
                        timer1.cancel();
                        timerTask = null;
                        timer1 = null;
                        finish();

                    }
                });
                builder1.setNegativeButton("继续学习",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                //     initStopDialog();
                                dialog.dismiss();
                            }
                        });
                builder1.create().show();
                return;
            }


            SharedPreferences sp1 = getSharedPreferences("CourseDetailsActivity",
                    Context.MODE_PRIVATE);
            String formats2 = sp1.getString("format", "");
            int courseLength2 = sp1.getInt("courseLength", 0);
            String[] splitformat2 = formats2.split(":");
            String formatstr7 = splitformat2[0];
            String formatstr8 = splitformat2[1];
            String formatstr9 = splitformat2[2];
            int iformat7 = Integer.valueOf(formatstr7);//转int
            int iformat8 = Integer.valueOf(formatstr8);//转int
            int iformat9 = Integer.valueOf(formatstr9);//转int
            int formattime2 = iformat7 * 3600 + iformat8 * 60 + iformat9 * 1;
            if (formattime2 < 60) {
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                View view1 = View.inflate(CourseDetailsActivity.this, R.layout.diolog_learn_layout, null);
                TextView tv_message = (TextView) view1.findViewById(R.id.message);//输入内容
                tv_message.setText("您本次学习未满一分钟，无法保存学习进度，退出后将重新学习本课程。");
                TextView btn_sure = (TextView) view1.findViewById(R.id.positiveButton);
                TextView btn_cancel = (TextView) view1.findViewById(R.id.negativeButton);
                btn_sure.setText("确认退出");
                btn_cancel.setText("继续学习");
                final AlertDialog dialog = builder.create();
                dialog.show();
                dialog.getWindow().setContentView(view1);
                dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                dialog.setCancelable(false);
                btn_sure.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        dialog.dismiss();
                        SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                                Context.MODE_PRIVATE);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.clear();
                        edit.commit();
//                        LoginUserBean userInfo = UserManger.getUserInfo();
//                        String userId = userInfo.getData().getUserId();
//                        SharedPreferences sp = getSharedPreferences("durationandformat1" + userId,
//                                Context.MODE_PRIVATE);
//                        int otcSn = sp.getInt("otcSn", 0);
//                        int learnsn = sp.getInt("learnsn", 0);
//                        String format = sp.getString("format"+ otcSn+learnsn, "");
//                        String imgurl = sp.getString("imgurl"+ otcSn+learnsn, "");
//                        int tcsn = sp.getInt("tcsn", 0);
//                        int sn = sp.getInt("sn", 0);
//                        String statYm = sp.getString("statYm", "");
//                        String orgId = sp.getString("orgId", "");
//                        String[] splitformat = format.split(":");
//                        String format1 = splitformat[0];
//                        String format2 = splitformat[1];
//                        String format3 = splitformat[2];
//                        int iformat1 = Integer.valueOf(format1);//转int
//                        int iformat2 = Integer.valueOf(format2);//转int
//                        int iformat3 = Integer.valueOf(format3);//转int
//                        int formattime = iformat1 * 3600 + iformat2 * 60 + iformat3 * 1;
//                        int photoMark = sp.getInt("photoMark", 0);
//                        if(photoMark==1)
//                        {
//                            int readLength = (formattime%60==0)?formattime/60:(formattime/60+1);//累计学习时间
//                            LogUtils.e("readLength",readLength+"");
//                            String firsttime = sp.getString("firsttime"+ otcSn, "");//第一次抓拍时间
//                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
//                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
//                            //                     String durationsub = duration.substring(3, 8);//截取字符串00:00:00变成00:00
//                            UserTcPhoto userTcPhoto = new UserTcPhoto();
//                            userTcPhoto.setSnapTime(firsttimesub);
//                            userTcPhoto.setUrl(imgurl);
//                            photoList.add(userTcPhoto);
//                            Gson gson = new Gson();
//                            String strphotoList = gson.toJson(photoList);
//                            LogUtils.e("strphotoList",strphotoList);
//                            initsavedata(sn,userId,orgId,tcsn,otcSn,learnsn,readLength,photoList);
//                        }else if(photoMark==0){
//                            int readLength = (formattime%60==0)?formattime/60:(formattime/60+1);//累计学习时间
//                            LogUtils.e("readLength",readLength+"");
//                            String firsttime = sp.getString("firsttime"+ otcSn, "");//第一次抓拍时间
//                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
//                            //      String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
//                            //                     String durationsub = duration.substring(3, 8);//截取字符串00:00:00变成00:00
//                            UserTcPhoto userTcPhoto = new UserTcPhoto();
//                            userTcPhoto.setSnapTime(firsttime);
//                            userTcPhoto.setUrl(imgurl);
//                            photoList.add(userTcPhoto);
//                            Gson gson = new Gson();
//                            String strphotoList = gson.toJson(photoList);
//                            LogUtils.e("strphotoList",strphotoList);
//                            initsavedata(sn,userId,orgId,tcsn,otcSn,learnsn,readLength,photoList);
//                        }
                        timerTask.cancel();
                        timer1.cancel();
                        timerTask = null;
                        timer1 = null;
                        finish();
                        //设置你的操作事项
                    }
                });

                btn_cancel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {


//                                LoginUserBean userInfo = UserManger.getUserInfo();
//                                String userId = userInfo.getData().getUserId();
//                                SharedPreferences sp = getSharedPreferences("durationandformat1"+userId,
//                                        Context.MODE_PRIVATE);
//                                int photoMark = sp.getInt("photoMark", 0);
//                                if(photoMark==1)
//                                {
//                                    Thread thread = new Thread(new Runnable() {
//                                        @Override
//                                        public void run() {
//                                            //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
//                                            mHandler.sendEmptyMessage(0);
//                                        }
//                                    });
//                                    thread.start();
//                                }else if(photoMark==0){
//                                    Thread thread = new Thread(new Runnable() {
//                                        @Override
//                                        public void run() {
//                                            //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
//                                            mHandler.sendEmptyMessage(2);
//                                        }
//                                    });
//                                    thread.start();
//                                }
                        //      tv_pause.setText("继续学习");
                        //  initStopDialog();
//                            LoginUserBean userInfo = UserManger.getUserInfo();
//                            String userId = userInfo.getData().getUserId();
//                            SharedPreferences sp = getSharedPreferences("durationandformat1" + userId,
//                                    Context.MODE_PRIVATE);
//                            int photoMark = sp.getInt("photoMark", 0);
//                            if (photoMark == 1) {
//                                Thread thread = new Thread(new Runnable() {
//                                    @Override
//                                    public void run() {
//                                        //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
//                                        mHandler.sendEmptyMessage(0);
//                                    }
//                                });
//                                thread.start();
//                            } else if (photoMark == 0) {
//                                Thread thread = new Thread(new Runnable() {
//                                    @Override
//                                    public void run() {
//                                        //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
//                                        mHandler.sendEmptyMessage(2);
//                                    }
//                                });
//                                thread.start();
//                            }

                        dialog.dismiss();
                    }
                });


            } else {
                if (formattime2 == courseLength2 * 60)//课程达到课程时长点保存相当于提交
                {
                    if (rowsList.size() != 0) {

                        for (int i = 0; i < rowsList.size(); i++) {
                            if (rowsList.get(i).isSelect() == false) {
                                TiShiDialog.Builder builder1 = new TiShiDialog.Builder(this);
                                builder1.setMessage("第" + (i + 1) + "测验题未答，请答题");
                                builder1.setTitle("提示:");
                                builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.dismiss();
                                        ;
                                        //设置你的操作事项
                                    }
                                });
                                builder1.create().show();

                                return;
                            } else {

                                if (rowsList.get(i).isLOOP() == false) {
                                    TiShiDialog.Builder builder1 = new TiShiDialog.Builder(this);
                                    builder1.setMessage("第" + (i + 1) + "测验题回答错误，请重新答题");
                                    builder1.setTitle("提示:");
                                    builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog, int which) {
                                            dialog.dismiss();
                                            ;
                                            //设置你的操作事项
                                        }
                                    });
                                    builder1.create().show();


                                    return;
                                }
                            }
                        }
                        //有题目接口
                        int tcsn = sp1.getInt("tcsn", 0);
                        int learnsn = sp1.getInt("learnsn", 0);
                        String orgId = sp1.getString("orgId", "");
                        if (photoMark == 1) {
                            LoginUserBean userInfo = UserManger.getUserInfo();
                            String userId = userInfo.getData().getUserId();//useid
                            String firsttime = sp1.getString("firsttime", "");//第一次抓拍时间
                            String imgurl = sp1.getString("imgurl", "");//第一次拍照图片地址获取
                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                            userTcPhoto.setUrl(imgurl);
                            userTcPhoto.setSnapTime(firsttimesub);
                            photoList.add(userTcPhoto);
                            Gson gson = new Gson();
                            String strphotoList = gson.toJson(photoList);
                            LogUtils.e("strphotoList", strphotoList);
                            mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                            mProgressDialog.setMessage("提交中...");
                            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                            mProgressDialog.setCancelable(false);
                            mProgressDialog.show();
                            new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength2, 1, photoList, this, 3);
                        } else if (photoMark == 0) {
                            LoginUserBean userInfo = UserManger.getUserInfo();
                            String userId = userInfo.getData().getUserId();//useid
                            String firsttime = sp1.getString("firsttime", "");//第一次抓拍时间
                            String imgurl = sp1.getString("imgurl", "");//第一次拍照图片地址获取
                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                            userTcPhoto.setUrl(imgurl);
                            userTcPhoto.setSnapTime(firsttime);
                            photoList.add(userTcPhoto);
                            Gson gson = new Gson();
                            String strphotoList = gson.toJson(photoList);
                            LogUtils.e("strphotoList", strphotoList);
                            mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                            mProgressDialog.setMessage("提交中...");
                            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                            mProgressDialog.setCancelable(false);
                            mProgressDialog.show();
                            new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength2, 1, photoList, this, 3);
                        } else if (photoMark == 2) {
                            LoginUserBean userInfo = UserManger.getUserInfo();
                            String userId = userInfo.getData().getUserId();//useid
                            String imgurl = sp1.getString("imgurl", "");
                            String imgurl1 = sp1.getString("imgurl1", "");
                            String firsttime = sp1.getString("firsttime", "");//第一次抓拍时间
                            String numFifthpartstr = sp1.getString("numFifthpartstr", "");//第二次抓拍时间
                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                            userTcPhoto.setUrl(imgurl);
                            userTcPhoto.setSnapTime(firsttimesub);
                            UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                            userTcPhoto1.setUrl(imgurl1);
                            userTcPhoto1.setSnapTime(numFifthpartstr1);
                            photoList.add(userTcPhoto);
                            photoList.add(userTcPhoto1);
                            Gson gson = new Gson();
                            String strphotoList = gson.toJson(photoList);
                            LogUtils.e("strphotoList", strphotoList);
                            mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                            mProgressDialog.setMessage("提交中...");
                            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                            mProgressDialog.setCancelable(false);
                            mProgressDialog.show();
                            new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength2, 1, photoList, this, 3);
                        } else if (photoMark == 3) {
                            LoginUserBean userInfo = UserManger.getUserInfo();
                            String userId = userInfo.getData().getUserId();//useid
                            String imgurl1 = sp1.getString("imgurl", "");
                            String firsttime = sp1.getString("firsttime", "");//第一次抓拍时间
                            String imgurl2 = sp1.getString("imgurl1", "");
                            String numsecondpartstr = sp1.getString("numsecondpartstr", "");//第二次抓拍时间
                            String imgurl3 = sp1.getString("imgurl2", "");
                            String numFifthpartstr = sp1.getString("numFifthpartstr", "");//第三次抓拍时间
                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                            userTcPhoto.setUrl(imgurl1);
                            userTcPhoto.setSnapTime(firsttimesub);
                            UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                            userTcPhoto1.setUrl(imgurl2);
                            userTcPhoto1.setSnapTime(numsecondpartstr1);
                            UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                            userTcPhoto2.setUrl(imgurl3);
                            userTcPhoto2.setSnapTime(numFifthpartstr1);
                            photoList.add(userTcPhoto);
                            photoList.add(userTcPhoto1);
                            photoList.add(userTcPhoto2);
                            Gson gson = new Gson();
                            String strphotoList = gson.toJson(photoList);
                            LogUtils.e("strphotoList", strphotoList);
                            mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                            mProgressDialog.setMessage("提交中...");
                            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                            mProgressDialog.setCancelable(false);
                            mProgressDialog.show();
                            new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength2, 1, photoList, this, 3);
                        } else if (photoMark == 4) {
                            LoginUserBean userInfo = UserManger.getUserInfo();
                            String userId = userInfo.getData().getUserId();//useid
                            String imgurl = sp1.getString("imgurl", "");
                            String imgurl1 = sp1.getString("imgurl1", "");
                            String imgurl2 = sp1.getString("imgurl2", "");
                            String imgurl3 = sp1.getString("imgurl3", "");
                            String firsttime = sp1.getString("firsttime", "");//第一次抓拍时间
                            String numsecondpartstr = sp1.getString("numsecondpartstr", "");//第二次抓拍时间
                            String numthirdpartstr = sp1.getString("numthirdpartstr", "");//第三次抓拍时间
                            String numFifthpartstr = sp1.getString("numFifthpartstr", "");//第四次抓拍时间
                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numthirdpartstr1 = numthirdpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                            userTcPhoto.setUrl(imgurl);
                            userTcPhoto.setSnapTime(firsttimesub);
                            UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                            userTcPhoto1.setUrl(imgurl1);
                            userTcPhoto1.setSnapTime(numsecondpartstr1);
                            UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                            userTcPhoto2.setUrl(imgurl2);
                            userTcPhoto2.setSnapTime(numthirdpartstr1);
                            UserTcPhoto userTcPhoto3 = new UserTcPhoto();
                            userTcPhoto3.setUrl(imgurl3);
                            userTcPhoto3.setSnapTime(numFifthpartstr1);
                            photoList.add(userTcPhoto);
                            photoList.add(userTcPhoto1);
                            photoList.add(userTcPhoto2);
                            photoList.add(userTcPhoto3);
                            Gson gson = new Gson();
                            String strphotoList = gson.toJson(photoList);
                            LogUtils.e("strphotoList", strphotoList);
                            mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                            mProgressDialog.setMessage("提交中...");
                            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                            mProgressDialog.setCancelable(false);
                            mProgressDialog.show();
                            new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength2, 1, photoList, this, 3);
                        } else if (photoMark == 5) {
                            LoginUserBean userInfo = UserManger.getUserInfo();
                            String userId = userInfo.getData().getUserId();//useid
                            String imgurl = sp1.getString("imgurl", "");
                            String imgurl1 = sp1.getString("imgurl1", "");
                            String imgurl2 = sp1.getString("imgurl2", "");
                            String imgurl3 = sp1.getString("imgurl3", "");
                            String imgurl4 = sp1.getString("imgurl4", "");
                            String firsttime = sp1.getString("firsttime", "");//第一次抓拍时间
                            String numsecondpartstr = sp1.getString("numsecondpartstr", "");//第二次抓拍时间
                            String numthirdpartstr = sp1.getString("numthirdpartstr", "");//第三次抓拍时间
                            String numfourpartstr = sp1.getString("numfourpartstr", "");//第四次抓拍时间
                            String numFifthpartstr = sp1.getString("numFifthpartstr", "");//第五次抓拍时间
                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numthirdpartstr1 = numthirdpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numfourpartstr1 = numfourpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                            userTcPhoto.setUrl(imgurl);
                            userTcPhoto.setSnapTime(firsttimesub);
                            UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                            userTcPhoto1.setUrl(imgurl1);
                            userTcPhoto1.setSnapTime(numsecondpartstr1);
                            UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                            userTcPhoto2.setUrl(imgurl2);
                            userTcPhoto2.setSnapTime(numthirdpartstr1);
                            UserTcPhoto userTcPhoto3 = new UserTcPhoto();
                            userTcPhoto3.setUrl(imgurl3);
                            userTcPhoto3.setSnapTime(numfourpartstr1);
                            UserTcPhoto userTcPhoto4 = new UserTcPhoto();
                            userTcPhoto4.setUrl(imgurl4);
                            userTcPhoto4.setSnapTime(numFifthpartstr1);
                            photoList.add(userTcPhoto);
                            photoList.add(userTcPhoto1);
                            photoList.add(userTcPhoto2);
                            photoList.add(userTcPhoto3);
                            photoList.add(userTcPhoto4);
                            Gson gson = new Gson();
                            String strphotoList = gson.toJson(photoList);
                            LogUtils.e("strphotoList", strphotoList);
                            mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                            mProgressDialog.setMessage("提交中...");
                            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                            mProgressDialog.setCancelable(false);
                            mProgressDialog.show();
                            new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength2, 1, photoList, this, 3);
                        }
                    } else {//无题目接口
                        int tcsn = sp1.getInt("tcsn", 0);
                        int learnsn = sp1.getInt("learnsn", 0);
                        String orgId = sp1.getString("orgId", "");
                        if (photoMark == 1) {
                            LoginUserBean userInfo = UserManger.getUserInfo();
                            String userId = userInfo.getData().getUserId();//useid
                            String firsttime = sp1.getString("firsttime", "");//第一次抓拍时间
                            String imgurl = sp1.getString("imgurl", "");//第一次拍照图片地址获取
                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                            userTcPhoto.setUrl(imgurl);
                            userTcPhoto.setSnapTime(firsttimesub);
                            photoList.add(userTcPhoto);
                            Gson gson = new Gson();
                            String strphotoList = gson.toJson(photoList);
                            LogUtils.e("strphotoList", strphotoList);
                            mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                            mProgressDialog.setMessage("提交中...");
                            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                            mProgressDialog.setCancelable(false);
                            mProgressDialog.show();
                            new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength2, 1, photoList, this, 3);
                        } else if (photoMark == 0) {
                            LoginUserBean userInfo = UserManger.getUserInfo();
                            String userId = userInfo.getData().getUserId();//useid
                            String firsttime = sp1.getString("firsttime", "");//第一次抓拍时间
                            String imgurl = sp1.getString("imgurl", "");//第一次拍照图片地址获取
                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                            userTcPhoto.setUrl(imgurl);
                            userTcPhoto.setSnapTime(firsttime);
                            photoList.add(userTcPhoto);
                            Gson gson = new Gson();
                            String strphotoList = gson.toJson(photoList);
                            LogUtils.e("strphotoList", strphotoList);
                            mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                            mProgressDialog.setMessage("提交中...");
                            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                            mProgressDialog.setCancelable(false);
                            mProgressDialog.show();
                            new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength2, 1, photoList, this, 3);
                        } else if (photoMark == 2) {
                            LoginUserBean userInfo = UserManger.getUserInfo();
                            String userId = userInfo.getData().getUserId();//useid
                            String imgurl = sp1.getString("imgurl", "");
                            String imgurl1 = sp1.getString("imgurl1", "");
                            String firsttime = sp1.getString("firsttime", "");//第一次抓拍时间
                            String numFifthpartstr = sp1.getString("numFifthpartstr", "");//第二次抓拍时间
                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                            userTcPhoto.setUrl(imgurl);
                            userTcPhoto.setSnapTime(firsttimesub);
                            UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                            userTcPhoto1.setUrl(imgurl1);
                            userTcPhoto1.setSnapTime(numFifthpartstr1);
                            photoList.add(userTcPhoto);
                            photoList.add(userTcPhoto1);
                            Gson gson = new Gson();
                            String strphotoList = gson.toJson(photoList);
                            LogUtils.e("strphotoList", strphotoList);
                            mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                            mProgressDialog.setMessage("提交中...");
                            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                            mProgressDialog.setCancelable(false);
                            mProgressDialog.show();
                            new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength2, 1, photoList, this, 3);
                        } else if (photoMark == 3) {
                            LoginUserBean userInfo = UserManger.getUserInfo();
                            String userId = userInfo.getData().getUserId();//useid
                            String imgurl1 = sp1.getString("imgurl", "");
                            String firsttime = sp1.getString("firsttime", "");//第一次抓拍时间
                            String imgurl2 = sp1.getString("imgurl1", "");
                            String numsecondpartstr = sp1.getString("numsecondpartstr", "");//第二次抓拍时间
                            String imgurl3 = sp1.getString("imgurl2", "");
                            String numFifthpartstr = sp1.getString("numFifthpartstr", "");//第三次抓拍时间
                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                            userTcPhoto.setUrl(imgurl1);
                            userTcPhoto.setSnapTime(firsttimesub);
                            UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                            userTcPhoto1.setUrl(imgurl2);
                            userTcPhoto1.setSnapTime(numsecondpartstr1);
                            UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                            userTcPhoto2.setUrl(imgurl3);
                            userTcPhoto2.setSnapTime(numFifthpartstr1);
                            photoList.add(userTcPhoto);
                            photoList.add(userTcPhoto1);
                            photoList.add(userTcPhoto2);
                            Gson gson = new Gson();
                            String strphotoList = gson.toJson(photoList);
                            LogUtils.e("strphotoList", strphotoList);
                            mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                            mProgressDialog.setMessage("提交中...");
                            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                            mProgressDialog.setCancelable(false);
                            mProgressDialog.show();
                            new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength2, 1, photoList, this, 3);
                        } else if (photoMark == 4) {
                            LoginUserBean userInfo = UserManger.getUserInfo();
                            String userId = userInfo.getData().getUserId();//useid
                            String imgurl = sp1.getString("imgurl", "");
                            String imgurl1 = sp1.getString("imgurl1", "");
                            String imgurl2 = sp1.getString("imgurl2", "");
                            String imgurl3 = sp1.getString("imgurl3", "");
                            String firsttime = sp1.getString("firsttime", "");//第一次抓拍时间
                            String numsecondpartstr = sp1.getString("numsecondpartstr", "");//第二次抓拍时间
                            String numthirdpartstr = sp1.getString("numthirdpartstr", "");//第三次抓拍时间
                            String numFifthpartstr = sp1.getString("numFifthpartstr", "");//第四次抓拍时间
                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numthirdpartstr1 = numthirdpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                            userTcPhoto.setUrl(imgurl);
                            userTcPhoto.setSnapTime(firsttimesub);
                            UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                            userTcPhoto1.setUrl(imgurl1);
                            userTcPhoto1.setSnapTime(numsecondpartstr1);
                            UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                            userTcPhoto2.setUrl(imgurl2);
                            userTcPhoto2.setSnapTime(numthirdpartstr1);
                            UserTcPhoto userTcPhoto3 = new UserTcPhoto();
                            userTcPhoto3.setUrl(imgurl3);
                            userTcPhoto3.setSnapTime(numFifthpartstr1);
                            photoList.add(userTcPhoto);
                            photoList.add(userTcPhoto1);
                            photoList.add(userTcPhoto2);
                            photoList.add(userTcPhoto3);
                            Gson gson = new Gson();
                            String strphotoList = gson.toJson(photoList);
                            LogUtils.e("strphotoList", strphotoList);
                            mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                            mProgressDialog.setMessage("提交中...");
                            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                            mProgressDialog.setCancelable(false);
                            mProgressDialog.show();
                            new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength2, 1, photoList, this, 3);
                        } else if (photoMark == 5) {
                            LoginUserBean userInfo = UserManger.getUserInfo();
                            String userId = userInfo.getData().getUserId();//useid
                            String imgurl = sp1.getString("imgurl", "");
                            String imgurl1 = sp1.getString("imgurl1", "");
                            String imgurl2 = sp1.getString("imgurl2", "");
                            String imgurl3 = sp1.getString("imgurl3", "");
                            String imgurl4 = sp1.getString("imgurl4", "");
                            String firsttime = sp1.getString("firsttime", "");//第一次抓拍时间
                            String numsecondpartstr = sp1.getString("numsecondpartstr", "");//第二次抓拍时间
                            String numthirdpartstr = sp1.getString("numthirdpartstr", "");//第三次抓拍时间
                            String numfourpartstr = sp1.getString("numfourpartstr", "");//第四次抓拍时间
                            String numFifthpartstr = sp1.getString("numFifthpartstr", "");//第五次抓拍时间
                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numthirdpartstr1 = numthirdpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numfourpartstr1 = numfourpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                            userTcPhoto.setUrl(imgurl);
                            userTcPhoto.setSnapTime(firsttimesub);
                            UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                            userTcPhoto1.setUrl(imgurl1);
                            userTcPhoto1.setSnapTime(numsecondpartstr1);
                            UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                            userTcPhoto2.setUrl(imgurl2);
                            userTcPhoto2.setSnapTime(numthirdpartstr1);
                            UserTcPhoto userTcPhoto3 = new UserTcPhoto();
                            userTcPhoto3.setUrl(imgurl3);
                            userTcPhoto3.setSnapTime(numfourpartstr1);
                            UserTcPhoto userTcPhoto4 = new UserTcPhoto();
                            userTcPhoto4.setUrl(imgurl4);
                            userTcPhoto4.setSnapTime(numFifthpartstr1);
                            photoList.add(userTcPhoto);
                            photoList.add(userTcPhoto1);
                            photoList.add(userTcPhoto2);
                            photoList.add(userTcPhoto3);
                            photoList.add(userTcPhoto4);
                            Gson gson = new Gson();
                            String strphotoList = gson.toJson(photoList);
                            LogUtils.e("strphotoList", strphotoList);
                            mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                            mProgressDialog.setMessage("提交中...");
                            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                            mProgressDialog.setCancelable(false);
                            mProgressDialog.show();
                            new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength2, 1, photoList, this, 3);
                        }
                    }
                } else if (formattime2 < courseLength2 * 60) {//滿一分鐘保存
//                        AlertDialog.Builder builder = new AlertDialog.Builder(this);
//                        View view1 = View
//                                .inflate(CourseDetailsActivity.this, R.layout.diolog_learn_layout, null);
//                        TextView tv_message = (TextView) view1
//                                .findViewById(R.id.message);//输入内容
//                        tv_message.setText("您的学习进度未保存，请点击“保存退出”按钮退出本课程学习，否则下次进入您将重新学习本课程。");
//                        TextView btn_sure = (TextView) view1.findViewById(R.id.positiveButton);
//                        TextView btn_cancel = (TextView) view1.findViewById(R.id.negativeButton);
//                        btn_cancel.setVisibility(View.GONE);
//                        btn_sure.setText("保存退出");
//                        final AlertDialog dialog = builder.create();
//                        dialog.show();
//                        dialog.getWindow().setContentView(view1);
//                        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
//                        dialog.setCancelable(false);
//                        btn_sure.setOnClickListener(new View.OnClickListener() {
//                            @Override
//                            public void onClick(View view) {
//                                dialog.dismiss();
                    LoginUserBean userInfo = UserManger.getUserInfo();
                    String userId1 = userInfo.getData().getUserId();
//                                SharedPreferences sp1 = getSharedPreferences("CourseDetailsActivity",
//                                        Context.MODE_PRIVATE);
//                                String formats3 = sp1.getString("format", "");
//                                String[] splitformat3= formats3.split(":");
//                                String formatstr4 = splitformat3[0];
//                                String formatstr5 = splitformat3[1];
//                                String formatstr6 = splitformat3[2];
//                                int iformat10 = Integer.valueOf(formatstr4);//转int
//                                int iformat11 = Integer.valueOf(formatstr5);//转int
//                                int iformat12 = Integer.valueOf(formatstr6);//转int
//                                int formattime3 = iformat10 * 3600 + iformat11 * 60 + iformat12 * 1;
                    //   String imgurl1 = sp.getString("imgurl", "");
                    int tcsn1 = sp1.getInt("tcsn", 0);
                    int learnsn1 = sp1.getInt("learnsn", 0);
                    String orgId1 = sp1.getString("orgId", "");
                    //   int readLength = (formattime2 % 60 != 0) ? formattime2 / 60+1: (formattime2 / 60);//累计学习时间
                    int readLength = (formattime2 % 60 == 0) ? formattime2 / 60 : (formattime2 / 60);//累计学习时间
                    if (photoMark == 1) {

                        LogUtils.e("readLength", readLength + "");
                        String firsttime = sp1.getString("firsttime", "");//第一次抓拍时间
                        String imgurl1 = sp1.getString("imgurl", "");
                        List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                        String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                        //                     String durationsub = duration.substring(3, 8);//截取字符串00:00:00变成00:00
                        UserTcPhoto userTcPhoto = new UserTcPhoto();
                        userTcPhoto.setSnapTime(firsttimesub);
                        userTcPhoto.setUrl(imgurl1);
                        photoList.add(userTcPhoto);
                        Gson gson = new Gson();
                        String strphotoList = gson.toJson(photoList);
                        LogUtils.e("strphotoList", strphotoList);
                        initsavedata(userId1, orgId1, tcsn1, learnsn1, readLength, photoList);
                    } else if (photoMark == 0) {
                        //          int readLength = (formattime3 % 60 == 0) ? formattime3 / 60 : (formattime3 / 60);//累计学习时间
                        LogUtils.e("readLength", readLength + "");
                        String firsttime = sp1.getString("firsttime", "");//第一次抓拍时间
                        String imgurl1 = sp1.getString("imgurl", "");
                        List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                        //      String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                        //                     String durationsub = duration.substring(3, 8);//截取字符串00:00:00变成00:00
                        UserTcPhoto userTcPhoto = new UserTcPhoto();
                        userTcPhoto.setSnapTime(firsttime);
                        userTcPhoto.setUrl(imgurl1);
                        photoList.add(userTcPhoto);
                        Gson gson = new Gson();
                        String strphotoList = gson.toJson(photoList);
                        LogUtils.e("strphotoList", strphotoList);
                        initsavedata(userId1, orgId1, tcsn1, learnsn1, readLength, photoList);
                    } else if (photoMark == 2) {
                        //     int readLength = (formattime3 % 60 == 0) ? formattime3 / 60 : (formattime3 / 60);//累计学习时间
                        LogUtils.e("readLength", readLength + "");
                        String imgurl1 = sp1.getString("imgurl", "");
                        String firsttime = sp1.getString("firsttime", "");//第一次抓拍时间
                        String imgurl2 = sp1.getString("imgurl1", "");
                        String numFifthpartstr = sp1.getString("numFifthpartstr", "");//第二次抓拍时间
                        List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                        String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00

                        UserTcPhoto userTcPhoto = new UserTcPhoto();
                        userTcPhoto.setSnapTime(firsttimesub);
                        userTcPhoto.setUrl(imgurl1);
                        photoList.add(userTcPhoto);
                        UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                        if (imgurl2.equals("")) {
                            userTcPhoto1.setSnapTime(numFifthpartstr);
                            userTcPhoto1.setUrl(imgurl2);

                        } else {
                            String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            userTcPhoto1.setSnapTime(numFifthpartstr1);
                            userTcPhoto1.setUrl(imgurl2);
                        }
                        photoList.add(userTcPhoto1);
                        Gson gson = new Gson();
                        String strphotoList = gson.toJson(photoList);
                        LogUtils.e("strphotoList", strphotoList);
                        initsavedata(userId1, orgId1, tcsn1, learnsn1, readLength, photoList);
                    } else if (photoMark == 3) {
                        //     int readLength = (formattime3 % 60 == 0) ? formattime3 / 60 : (formattime3 / 60);//累计学习时间
                        LogUtils.e("readLength", readLength + "");
                        String imgurl1 = sp1.getString("imgurl", "");
                        String firsttime = sp1.getString("firsttime", "");//第一次抓拍时间
                        String imgurl2 = sp1.getString("imgurl1", "");
                        String numsecondpartstr = sp1.getString("numsecondpartstr", "");//第二次抓拍时间
                        String imgurl3 = sp1.getString("imgurl2", "");
                        String numFifthpartstr = sp1.getString("numFifthpartstr", "");//第三次抓拍时间
                        List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                        String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00

                        UserTcPhoto userTcPhoto = new UserTcPhoto();
                        userTcPhoto.setSnapTime(firsttimesub);
                        userTcPhoto.setUrl(imgurl1);
                        photoList.add(userTcPhoto);
                        UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                        if (imgurl2.equals("")) {
                            userTcPhoto1.setSnapTime(numsecondpartstr);
                            userTcPhoto1.setUrl(imgurl2);

                        } else {
                            String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            userTcPhoto1.setSnapTime(numsecondpartstr1);
                            userTcPhoto1.setUrl(imgurl2);
                        }
                        photoList.add(userTcPhoto1);
                        UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                        if (imgurl3.equals("")) {
                            userTcPhoto2.setSnapTime(numFifthpartstr);
                            userTcPhoto2.setUrl(imgurl3);

                        } else {
                            String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            userTcPhoto2.setSnapTime(numFifthpartstr1);
                            userTcPhoto2.setUrl(imgurl3);
                        }
                        photoList.add(userTcPhoto2);

                        Gson gson = new Gson();
                        String strphotoList = gson.toJson(photoList);
                        LogUtils.e("strphotoList", strphotoList);
                        initsavedata(userId1, orgId1, tcsn1, learnsn1, readLength, photoList);
                    } else if (photoMark == 4) {
                        //    int readLength = (formattime3 % 60 == 0) ? formattime3 / 60 : (formattime3 / 60);//累计学习时间
                        LogUtils.e("readLength", readLength + "");
                        String imgurl1 = sp1.getString("imgurl", "");
                        String firsttime = sp1.getString("firsttime", "");//第一次抓拍时间
                        String imgurl2 = sp1.getString("imgurl1", "");
                        String numsecondpartstr = sp1.getString("numsecondpartstr", "");//第二次抓拍时间
                        String imgurl3 = sp1.getString("imgurl2", "");
                        String numthirdpartstr = sp1.getString("numthirdpartstr", "");//第三次抓拍时间
                        String imgurl4 = sp1.getString("imgurl3", "");
                        String numFifthpartstr = sp1.getString("numFifthpartstr", "");//第四次抓拍时间
                        List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                        String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00

                        UserTcPhoto userTcPhoto = new UserTcPhoto();
                        userTcPhoto.setSnapTime(firsttimesub);
                        userTcPhoto.setUrl(imgurl1);
                        photoList.add(userTcPhoto);
                        UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                        if (imgurl2.equals("")) {
                            userTcPhoto1.setSnapTime(numsecondpartstr);
                            userTcPhoto1.setUrl(imgurl2);

                        } else {
                            String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            userTcPhoto1.setSnapTime(numsecondpartstr1);
                            userTcPhoto1.setUrl(imgurl2);
                        }
                        photoList.add(userTcPhoto1);
                        UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                        if (imgurl3.equals("")) {
                            userTcPhoto2.setSnapTime(numthirdpartstr);
                            userTcPhoto2.setUrl(imgurl3);

                        } else {
                            String numthirdpartstr1 = numthirdpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            userTcPhoto2.setSnapTime(numthirdpartstr1);
                            userTcPhoto2.setUrl(imgurl3);
                        }
                        photoList.add(userTcPhoto2);
                        UserTcPhoto userTcPhoto3 = new UserTcPhoto();
                        if (imgurl4.equals("")) {
                            userTcPhoto3.setSnapTime(numFifthpartstr);
                            userTcPhoto3.setUrl(imgurl4);

                        } else {
                            String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            userTcPhoto3.setSnapTime(numFifthpartstr1);
                            userTcPhoto3.setUrl(imgurl4);
                        }
                        photoList.add(userTcPhoto3);

                        Gson gson = new Gson();
                        String strphotoList = gson.toJson(photoList);
                        LogUtils.e("strphotoList", strphotoList);
                        initsavedata(userId1, orgId1, tcsn1, learnsn1, readLength, photoList);
                    } else if (photoMark == 5) {
                        //     int readLength = (formattime3 % 60 == 0) ? formattime3 / 60 : (formattime3 / 60);//累计学习时间
                        LogUtils.e("readLength", readLength + "");
                        String imgurl1 = sp1.getString("imgurl", "");
                        String firsttime = sp1.getString("firsttime", "");//第一次抓拍时间
                        String imgurl2 = sp1.getString("imgurl1", "");
                        String numsecondpartstr = sp1.getString("numsecondpartstr", "");//第二次抓拍时间
                        String imgurl3 = sp1.getString("imgurl2", "");
                        String numthirdpartstr = sp1.getString("numthirdpartstr", "");//第三次抓拍时间
                        String imgurl4 = sp1.getString("imgurl3", "");
                        String numfourpartstr = sp1.getString("numfourpartstr", "");//第四次抓拍时间
                        String imgurl5 = sp1.getString("imgurl4", "");
                        String numFifthpartstr = sp1.getString("numFifthpartstr", "");//第五次抓拍时间
                        List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                        String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00

                        UserTcPhoto userTcPhoto = new UserTcPhoto();
                        userTcPhoto.setSnapTime(firsttimesub);
                        userTcPhoto.setUrl(imgurl1);
                        photoList.add(userTcPhoto);
                        UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                        if (imgurl2.equals("")) {
                            userTcPhoto1.setSnapTime(numsecondpartstr);
                            userTcPhoto1.setUrl(imgurl2);

                        } else {
                            String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            userTcPhoto1.setSnapTime(numsecondpartstr1);
                            userTcPhoto1.setUrl(imgurl2);
                        }
                        photoList.add(userTcPhoto1);
                        UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                        if (imgurl3.equals("")) {
                            userTcPhoto2.setSnapTime(numthirdpartstr);
                            userTcPhoto2.setUrl(imgurl3);

                        } else {
                            String numthirdpartstr1 = numthirdpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            userTcPhoto2.setSnapTime(numthirdpartstr1);
                            userTcPhoto2.setUrl(imgurl3);
                        }
                        photoList.add(userTcPhoto2);
                        UserTcPhoto userTcPhoto3 = new UserTcPhoto();
                        if (imgurl4.equals("")) {
                            userTcPhoto3.setSnapTime(numfourpartstr);
                            userTcPhoto3.setUrl(imgurl4);

                        } else {
                            String numfourpartstr1 = numfourpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            userTcPhoto3.setSnapTime(numfourpartstr1);
                            userTcPhoto3.setUrl(imgurl4);
                        }
                        photoList.add(userTcPhoto3);
                        UserTcPhoto userTcPhoto4 = new UserTcPhoto();
                        if (imgurl5.equals("")) {
                            userTcPhoto4.setSnapTime(numFifthpartstr);
                            userTcPhoto4.setUrl(imgurl5);

                        } else {
                            String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                            userTcPhoto4.setSnapTime(numFifthpartstr1);
                            userTcPhoto4.setUrl(imgurl5);
                        }
                        photoList.add(userTcPhoto4);
                        Gson gson = new Gson();
                        String strphotoList = gson.toJson(photoList);
                        LogUtils.e("strphotoList", strphotoList);
                        initsavedata(userId1, orgId1, tcsn1, learnsn1, readLength, photoList);
                    }
//                            }
//                        });
                }
            }
            //                case R.id.img_course2://暂停功能
//                    if (tv_pause.getText().toString().equals("暂停学习")) {
//                        timerTask.cancel();
//                        initStopDialog();
//                        tv_pause.setText("继续学习");
//                    } else if (tv_pause.getText().toString().equals("继续学习")) {
//                        tv_pause.setText("暂停学习");
//
//                        if (photoMark == 1) {
//                            Thread thread = new Thread(new Runnable() {
//                                @Override
//                                public void run() {
//                                    //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
//                                    mHandler.sendEmptyMessage(0);
//                                }
//                            });
//                            thread.start();
//                        } else if (photoMark == 0) {
//                            Thread thread = new Thread(new Runnable() {
//                                @Override
//                                public void run() {
//                                    //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
//                                    mHandler.sendEmptyMessage(2);
//                                }
//                            });
//                            thread.start();
//                        }
//                    }
            //                   break;
        } else if (id == R.id.tv_course10) {//提交

            if (Utils.isFastClicker()) {
                return;
            }
            if (setYm.equals("")) {

                TiShiDialog.Builder builder1 = new TiShiDialog.Builder(CourseDetailsActivity.this);
                builder1.setMessage("仅查看,不能提交");
                builder1.setTitle("提示:");
                builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        ;
                        //设置你的操作事项

                    }
                });
                builder1.create().show();
                return;
            }

            SharedPreferences sp2 = getSharedPreferences("CourseDetailsActivity",
                    Context.MODE_PRIVATE);
            String format = sp2.getString("format", "");
            int num = sp2.getInt("num", 0);
            int tcsn = sp2.getInt("tcsn", 0);
            int learnsn = sp2.getInt("learnsn", 0);
            String orgId = sp2.getString("orgId", "");
            int courseLength = sp2.getInt("courseLength", 0);
            String imgurl = sp2.getString("imgurl", "");//第一次拍照图片地址获取
            String[] splitformat = format.split(":");
            String format1 = splitformat[0];
            String format2 = splitformat[1];
            String format3 = splitformat[2];
            int iformat1 = Integer.valueOf(format1);//转int
            int iformat2 = Integer.valueOf(format2);//转int
            int iformat3 = Integer.valueOf(format3);//转int
            int formattime = iformat1 * 3600 + iformat2 * 60 + iformat3 * 1;
            if (formattime < num) {
                //  String numTime = getNumTime(num);
                TiShiDialog.Builder builder1 = new TiShiDialog.Builder(this);
                builder1.setMessage("学习时间不足，不能提交。");
                builder1.setTitle("提示:");
                builder1.setPositiveButton("继续学习", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        ;
                        //设置你的操作事项
                    }
                });
                builder1.create().show();


            } else {

                if (rowsList.size() != 0) {

                    for (int i = 0; i < rowsList.size(); i++) {
                        if (rowsList.get(i).isSelect() == false) {
                            TiShiDialog.Builder builder1 = new TiShiDialog.Builder(this);
                            builder1.setMessage("第" + (i + 1) + "测验题未答，请答题");
                            builder1.setTitle("提示:");
                            builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    ;
                                    //设置你的操作事项
                                }
                            });
                            builder1.create().show();

                            return;
                        } else {

                            if (rowsList.get(i).isLOOP() == false) {
                                TiShiDialog.Builder builder1 = new TiShiDialog.Builder(this);
                                builder1.setMessage("第" + (i + 1) + "测验题回答错误，请重新答题");
                                builder1.setTitle("提示:");
                                builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.dismiss();
                                        ;
                                        //设置你的操作事项
                                    }
                                });
                                builder1.create().show();


                                return;
                            }
                        }
                    }

                    if (photoMark == 1) {
                        //有题目调提交接口

                        //   int readLength = (formattime % 60 == 0) ? formattime / 60 : (formattime / 60 + 1);//累计学习时间
                        LoginUserBean userInfo = UserManger.getUserInfo();
                        String userId = userInfo.getData().getUserId();//useid


                        if (imgurl.equals("")) {
                            TiShiDialog.Builder builder1 = new TiShiDialog.Builder(this);
                            builder1.setMessage("请等待拍照");
                            builder1.setTitle("提示:");
                            builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    //设置你的操作事项
                                }
                            });

                            builder1.create().show();
                            return;
                        }
                        String firsttime = sp2.getString("firsttime", "");//第一次抓拍时间
                        String imgurl1 = sp2.getString("imgurl", "");
                        String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                        //                      String durationsub = duration.substring(3, 8);//截取字符串00:00:00变成00:00
                        List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                        UserTcPhoto userTcPhoto = new UserTcPhoto();
                        userTcPhoto.setSnapTime(firsttimesub);
                        userTcPhoto.setUrl(imgurl1);
                        photoList.add(userTcPhoto);
//                        if(!imgurl1.equals(""))
//                        {
//                            UserTcPhoto userTcPhoto1 = new UserTcPhoto();
//                            userTcPhoto1.setSnapTime(durationsub);
//                            userTcPhoto1.setUrl(imgurl1);
//                            photoList.add(userTcPhoto1);
//                        }
                        Gson gson = new Gson();
                        String strphotoList = gson.toJson(photoList);
                        LogUtils.e("strphotoList", strphotoList);
                        //  showLoadingDialog("提交中");
                        mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                        mProgressDialog.setMessage("提交中...");
                        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        mProgressDialog.setCancelable(false);
                        mProgressDialog.show();
                        new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength, 1, photoList, this, 3);
                    } else if (photoMark == 0) {
                        //有题目调提交接口
                        LoginUserBean userInfo = UserManger.getUserInfo();
                        String userId = userInfo.getData().getUserId();//useid
                        String imgurl1 = sp2.getString("imgurl", "");
                        String firsttime = sp2.getString("firsttime", "");//第一次抓拍时间
                        List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                        UserTcPhoto userTcPhoto = new UserTcPhoto();
                        userTcPhoto.setSnapTime(firsttime);
                        userTcPhoto.setUrl(imgurl1);
                        photoList.add(userTcPhoto);
                        Gson gson = new Gson();
                        String strphotoList = gson.toJson(photoList);
                        LogUtils.e("strphotoList", strphotoList);
                        //  showLoadingDialog("提交中");
                        mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                        mProgressDialog.setMessage("提交中...");
                        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        mProgressDialog.setCancelable(false);
                        mProgressDialog.show();
                        new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength, 1, photoList, this, 3);
                    } else if (photoMark == 2) {
                        LoginUserBean userInfo = UserManger.getUserInfo();
                        String userId = userInfo.getData().getUserId();//useid
                        String imgurl1 = sp2.getString("imgurl", "");
                        String imgurl2 = sp2.getString("imgurl1", "");
                        if (imgurl1.equals("")) {
                            timerTask.cancel();
                            initDialog();
                            return;
                        }
                        if (imgurl2.equals("")) {
                            timerTask.cancel();
                            initDialog3();
                            return;
                        }


                        String firsttime = sp2.getString("firsttime", "");//第一次抓拍时间
                        String numFifthpartstr = sp2.getString("numFifthpartstr", "");//第二次抓拍时间
                        String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                        UserTcPhoto userTcPhoto = new UserTcPhoto();
                        userTcPhoto.setUrl(imgurl1);
                        userTcPhoto.setSnapTime(firsttimesub);
                        UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                        userTcPhoto1.setUrl(imgurl2);
                        userTcPhoto1.setSnapTime(numFifthpartstr1);
                        photoList.add(userTcPhoto);
                        photoList.add(userTcPhoto1);
                        Gson gson = new Gson();
                        String strphotoList = gson.toJson(photoList);
                        LogUtils.e("strphotoList", strphotoList);
                        mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                        mProgressDialog.setMessage("提交中...");
                        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        mProgressDialog.setCancelable(false);
                        mProgressDialog.show();
                        new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength, 1, photoList, this, 3);
                    } else if (photoMark == 3) {
                        LoginUserBean userInfo = UserManger.getUserInfo();
                        String userId = userInfo.getData().getUserId();//useid
                        String imgurl1 = sp2.getString("imgurl", "");
                        String imgurl2 = sp2.getString("imgurl1", "");
                        String imgurl3 = sp2.getString("imgurl2", "");
                        if (imgurl1.equals("")) {
                            timerTask.cancel();
                            initDialog();
                            return;
                        }
                        if (imgurl2.equals("")) {
                            timerTask.cancel();
                            initDialog3();
                            return;
                        }
                        if (imgurl3.equals("")) {
                            timerTask.cancel();
                            initDialog4();
                            return;
                        }


                        String firsttime = sp2.getString("firsttime", "");//第一次抓拍时间
                        String numsecondpartstr = sp2.getString("numsecondpartstr", "");//第二次抓拍时间
                        String numFifthpartstr = sp2.getString("numFifthpartstr", "");//第三次抓拍时间
                        String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                        UserTcPhoto userTcPhoto = new UserTcPhoto();
                        userTcPhoto.setUrl(imgurl1);
                        userTcPhoto.setSnapTime(firsttimesub);
                        UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                        userTcPhoto1.setUrl(imgurl2);
                        userTcPhoto1.setSnapTime(numsecondpartstr1);
                        UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                        userTcPhoto2.setUrl(imgurl3);
                        userTcPhoto2.setSnapTime(numFifthpartstr1);
                        photoList.add(userTcPhoto);
                        photoList.add(userTcPhoto1);
                        photoList.add(userTcPhoto2);
                        Gson gson = new Gson();
                        String strphotoList = gson.toJson(photoList);
                        LogUtils.e("strphotoList", strphotoList);
                        mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                        mProgressDialog.setMessage("提交中...");
                        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        mProgressDialog.setCancelable(false);
                        mProgressDialog.show();
                        new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength, 1, photoList, this, 3);
                    } else if (photoMark == 4) {
                        LoginUserBean userInfo = UserManger.getUserInfo();
                        String userId = userInfo.getData().getUserId();//useid
                        String imgurl1 = sp2.getString("imgurl", "");
                        String imgurl2 = sp2.getString("imgurl1", "");
                        String imgurl3 = sp2.getString("imgurl2", "");
                        String imgurl4 = sp2.getString("imgurl3", "");
                        if (imgurl1.equals("")) {
                            timerTask.cancel();
                            initDialog();
                            return;
                        }
                        if (imgurl2.equals("")) {
                            timerTask.cancel();
                            initDialog3();
                            return;
                        }
                        if (imgurl3.equals("")) {
                            timerTask.cancel();
                            initDialog4();
                            return;
                        }
                        if (imgurl4.equals("")) {
                            timerTask.cancel();
                            initDialog5();
                            return;
                        }

                        String firsttime = sp2.getString("firsttime", "");//第一次抓拍时间
                        String numsecondpartstr = sp2.getString("numsecondpartstr", "");//第二次抓拍时间
                        String numthirdpartstr = sp2.getString("numthirdpartstr", "");//第三次抓拍时间
                        String numFifthpartstr = sp2.getString("numFifthpartstr", "");//第四次抓拍时间
                        String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numthirdpartstr1 = numthirdpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                        UserTcPhoto userTcPhoto = new UserTcPhoto();
                        userTcPhoto.setUrl(imgurl1);
                        userTcPhoto.setSnapTime(firsttimesub);
                        UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                        userTcPhoto1.setUrl(imgurl2);
                        userTcPhoto1.setSnapTime(numsecondpartstr1);
                        UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                        userTcPhoto2.setUrl(imgurl3);
                        userTcPhoto2.setSnapTime(numthirdpartstr1);
                        UserTcPhoto userTcPhoto3 = new UserTcPhoto();
                        userTcPhoto3.setUrl(imgurl4);
                        userTcPhoto3.setSnapTime(numFifthpartstr1);
                        photoList.add(userTcPhoto);
                        photoList.add(userTcPhoto1);
                        photoList.add(userTcPhoto2);
                        photoList.add(userTcPhoto3);
                        Gson gson = new Gson();
                        String strphotoList = gson.toJson(photoList);
                        LogUtils.e("strphotoList", strphotoList);
                        mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                        mProgressDialog.setMessage("提交中...");
                        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        mProgressDialog.setCancelable(false);
                        mProgressDialog.show();
                        new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength, 1, photoList, this, 3);
                    } else if (photoMark == 5) {
                        LoginUserBean userInfo = UserManger.getUserInfo();
                        String userId = userInfo.getData().getUserId();//useid
                        String imgurl1 = sp2.getString("imgurl", "");
                        String imgurl2 = sp2.getString("imgurl1", "");
                        String imgurl3 = sp2.getString("imgurl2", "");
                        String imgurl4 = sp2.getString("imgurl3", "");
                        String imgurl5 = sp2.getString("imgurl4", "");
                        if (imgurl1.equals("")) {
                            timerTask.cancel();
                            initDialog();
                            return;
                        }
                        if (imgurl2.equals("")) {
                            timerTask.cancel();
                            initDialog3();
                            return;
                        }
                        if (imgurl3.equals("")) {
                            timerTask.cancel();
                            initDialog4();
                            return;
                        }
                        if (imgurl4.equals("")) {
                            timerTask.cancel();
                            initDialog5();
                            return;
                        }
                        if (imgurl5.equals("")) {
                            timerTask.cancel();
                            initDialog6();
                            return;
                        }
                        String firsttime = sp2.getString("firsttime", "");//第一次抓拍时间
                        String numsecondpartstr = sp2.getString("numsecondpartstr", "");//第二次抓拍时间
                        String numthirdpartstr = sp2.getString("numthirdpartstr", "");//第三次抓拍时间
                        String numfourpartstr = sp2.getString("numfourpartstr", "");//第四次抓拍时间
                        String numFifthpartstr = sp2.getString("numFifthpartstr", "");//第五次抓拍时间
                        String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numthirdpartstr1 = numthirdpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numfourpartstr1 = numfourpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                        UserTcPhoto userTcPhoto = new UserTcPhoto();
                        userTcPhoto.setUrl(imgurl1);
                        userTcPhoto.setSnapTime(firsttimesub);
                        UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                        userTcPhoto1.setUrl(imgurl2);
                        userTcPhoto1.setSnapTime(numsecondpartstr1);
                        UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                        userTcPhoto2.setUrl(imgurl3);
                        userTcPhoto2.setSnapTime(numthirdpartstr1);
                        UserTcPhoto userTcPhoto3 = new UserTcPhoto();
                        userTcPhoto3.setUrl(imgurl4);
                        userTcPhoto3.setSnapTime(numfourpartstr1);
                        UserTcPhoto userTcPhoto4 = new UserTcPhoto();
                        userTcPhoto4.setUrl(imgurl5);
                        userTcPhoto4.setSnapTime(numFifthpartstr1);
                        photoList.add(userTcPhoto);
                        photoList.add(userTcPhoto1);
                        photoList.add(userTcPhoto2);
                        photoList.add(userTcPhoto3);
                        photoList.add(userTcPhoto4);
                        Gson gson = new Gson();
                        String strphotoList = gson.toJson(photoList);
                        LogUtils.e("strphotoList", strphotoList);
                        mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                        mProgressDialog.setMessage("提交中...");
                        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        mProgressDialog.setCancelable(false);
                        mProgressDialog.show();
                        new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength, 1, photoList, this, 3);
                    }
                } else {
                    if (photoMark == 1) {
                        //没有题目调提交接口
                        //     int readLength = (formattime % 60 == 0) ? formattime / 60 : (formattime / 60 + 1);//累计学习时间
                        LoginUserBean userInfo = UserManger.getUserInfo();
                        String userId = userInfo.getData().getUserId();//useid

                        if (imgurl.equals("")) {
                            TiShiDialog.Builder builder1 = new TiShiDialog.Builder(this);
                            builder1.setMessage("请等待拍照");
                            builder1.setTitle("提示:");
                            builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    //设置你的操作事项
                                }
                            });

                            builder1.create().show();
                            return;
                        }
                        String firsttime = sp2.getString("firsttime", "");//第一次抓拍时间
                        String imgurl1 = sp2.getString("imgurl", "");
//                        String duration = sp.getString("duration", "");//第二次抓拍时间
                        String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
//                        String durationsub = duration.substring(3,8);//截取字符串00:00:00变成00:00
                        List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                        UserTcPhoto userTcPhoto = new UserTcPhoto();
                        userTcPhoto.setUrl(imgurl1);
                        userTcPhoto.setSnapTime(firsttimesub);
                        photoList.add(userTcPhoto);
//                        if(!imgurl1.equals(""))
//                        {
//                            UserTcPhoto userTcPhoto1 = new UserTcPhoto();
//                            userTcPhoto1.setSnapTime(durationsub);
//                            userTcPhoto1.setUrl(imgurl1);
//                            photoList.add(userTcPhoto1);
//                        }
                        Gson gson = new Gson();
                        String strphotoList = gson.toJson(photoList);
                        LogUtils.e("strphotoList", strphotoList);
                        //          showLoadingDialog("提交中");
                        mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                        mProgressDialog.setMessage("提交中...");
                        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        mProgressDialog.setCancelable(false);
                        mProgressDialog.show();
                        new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength, 1, photoList, this, 3);
                    } else if (photoMark == 0) {
                        //没有题目调提交接口
                        String imgurl1 = sp2.getString("imgurl", "");
                        LoginUserBean userInfo = UserManger.getUserInfo();
                        String userId = userInfo.getData().getUserId();//useid
                        String firsttime = sp2.getString("firsttime", "");//第一次抓拍时间
//                        String imgurl1 = spp.getString("imgurl1", "");//第二次拍照图片地址获取
//                        String duration = sp.getString("duration", "");//第二次抓拍时间
                        //              String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
//                        String durationsub = duration.substring(3,8);//截取字符串00:00:00变成00:00
                        List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                        UserTcPhoto userTcPhoto = new UserTcPhoto();
                        userTcPhoto.setUrl(imgurl1);
                        userTcPhoto.setSnapTime(firsttime);
                        photoList.add(userTcPhoto);
                        Gson gson = new Gson();
                        String strphotoList = gson.toJson(photoList);
                        LogUtils.e("strphotoList", strphotoList);
                        //          showLoadingDialog("提交中");
                        mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                        mProgressDialog.setMessage("提交中...");
                        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        mProgressDialog.setCancelable(false);
                        mProgressDialog.show();
                        new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength, 1, photoList, this, 3);
                    } else if (photoMark == 2) {
                        LoginUserBean userInfo = UserManger.getUserInfo();
                        String userId = userInfo.getData().getUserId();//useid
                        String imgurl1 = sp2.getString("imgurl", "");
                        String imgurl2 = sp2.getString("imgurl1", "");
                        if (imgurl1.equals("")) {
                            timerTask.cancel();
                            initDialog();
                            return;
                        }
                        if (imgurl2.equals("")) {
                            timerTask.cancel();
                            initDialog3();
                            return;
                        }
                        String firsttime = sp2.getString("firsttime", "");//第一次抓拍时间
                        String numFifthpartstr = sp2.getString("numFifthpartstr", "");//第二次抓拍时间
                        String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                        UserTcPhoto userTcPhoto = new UserTcPhoto();
                        userTcPhoto.setUrl(imgurl1);
                        userTcPhoto.setSnapTime(firsttimesub);
                        UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                        userTcPhoto1.setUrl(imgurl2);
                        userTcPhoto1.setSnapTime(numFifthpartstr1);
                        photoList.add(userTcPhoto);
                        photoList.add(userTcPhoto1);
                        Gson gson = new Gson();
                        String strphotoList = gson.toJson(photoList);
                        LogUtils.e("strphotoList", strphotoList);
                        mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                        mProgressDialog.setMessage("提交中...");
                        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        mProgressDialog.setCancelable(false);
                        mProgressDialog.show();
                        new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength, 1, photoList, this, 3);
                    } else if (photoMark == 3) {
                        LoginUserBean userInfo = UserManger.getUserInfo();
                        String userId = userInfo.getData().getUserId();//useid
                        String imgurl1 = sp2.getString("imgurl", "");
                        String imgurl2 = sp2.getString("imgurl1", "");
                        String imgurl3 = sp2.getString("imgurl2", "");
                        if (imgurl1.equals("")) {
                            timerTask.cancel();
                            initDialog();
                            return;
                        }
                        if (imgurl2.equals("")) {
                            timerTask.cancel();
                            initDialog3();
                            return;
                        }
                        if (imgurl3.equals("")) {
                            timerTask.cancel();
                            initDialog4();
                            return;
                        }

                        String firsttime = sp2.getString("firsttime", "");//第一次抓拍时间
                        String numsecondpartstr = sp2.getString("numsecondpartstr", "");//第二次抓拍时间
                        String numFifthpartstr = sp2.getString("numFifthpartstr", "");//第三次抓拍时间
                        String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                        UserTcPhoto userTcPhoto = new UserTcPhoto();
                        userTcPhoto.setUrl(imgurl1);
                        userTcPhoto.setSnapTime(firsttimesub);
                        UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                        userTcPhoto1.setUrl(imgurl2);
                        userTcPhoto1.setSnapTime(numsecondpartstr1);
                        UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                        userTcPhoto2.setUrl(imgurl3);
                        userTcPhoto2.setSnapTime(numFifthpartstr1);
                        photoList.add(userTcPhoto);
                        photoList.add(userTcPhoto1);
                        photoList.add(userTcPhoto2);
                        Gson gson = new Gson();
                        String strphotoList = gson.toJson(photoList);
                        LogUtils.e("strphotoList", strphotoList);
                        mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                        mProgressDialog.setMessage("提交中...");
                        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        mProgressDialog.setCancelable(false);
                        mProgressDialog.show();
                        new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength, 1, photoList, this, 3);
                    } else if (photoMark == 4) {
                        LoginUserBean userInfo = UserManger.getUserInfo();
                        String userId = userInfo.getData().getUserId();//useid
                        String imgurl1 = sp2.getString("imgurl", "");
                        String imgurl2 = sp2.getString("imgurl1", "");
                        String imgurl3 = sp2.getString("imgurl2", "");
                        String imgurl4 = sp2.getString("imgurl3", "");
                        if (imgurl1.equals("")) {
                            timerTask.cancel();
                            initDialog();
                            return;
                        }
                        if (imgurl2.equals("")) {
                            timerTask.cancel();
                            initDialog3();
                            return;
                        }
                        if (imgurl3.equals("")) {
                            timerTask.cancel();
                            initDialog4();
                            return;
                        }
                        if (imgurl4.equals("")) {
                            timerTask.cancel();
                            initDialog5();
                            return;
                        }

                        String firsttime = sp2.getString("firsttime", "");//第一次抓拍时间
                        String numsecondpartstr = sp2.getString("numsecondpartstr", "");//第二次抓拍时间
                        String numthirdpartstr = sp2.getString("numthirdpartstr", "");//第三次抓拍时间
                        String numFifthpartstr = sp2.getString("numFifthpartstr", "");//第四次抓拍时间
                        String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numthirdpartstr1 = numthirdpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                        UserTcPhoto userTcPhoto = new UserTcPhoto();
                        userTcPhoto.setUrl(imgurl1);
                        userTcPhoto.setSnapTime(firsttimesub);
                        UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                        userTcPhoto1.setUrl(imgurl2);
                        userTcPhoto1.setSnapTime(numsecondpartstr1);
                        UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                        userTcPhoto2.setUrl(imgurl3);
                        userTcPhoto2.setSnapTime(numthirdpartstr1);
                        UserTcPhoto userTcPhoto3 = new UserTcPhoto();
                        userTcPhoto3.setUrl(imgurl4);
                        userTcPhoto3.setSnapTime(numFifthpartstr1);
                        photoList.add(userTcPhoto);
                        photoList.add(userTcPhoto1);
                        photoList.add(userTcPhoto2);
                        photoList.add(userTcPhoto3);
                        Gson gson = new Gson();
                        String strphotoList = gson.toJson(photoList);
                        LogUtils.e("strphotoList", strphotoList);
                        mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                        mProgressDialog.setMessage("提交中...");
                        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        mProgressDialog.setCancelable(false);
                        mProgressDialog.show();
                        new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength, 1, photoList, this, 3);
                    } else if (photoMark == 5) {
                        LoginUserBean userInfo = UserManger.getUserInfo();
                        String userId = userInfo.getData().getUserId();//useid
                        String imgurl1 = sp2.getString("imgurl", "");
                        String imgurl2 = sp2.getString("imgurl1", "");
                        String imgurl3 = sp2.getString("imgurl2", "");
                        String imgurl4 = sp2.getString("imgurl3", "");
                        String imgurl5 = sp2.getString("imgurl4", "");
                        if (imgurl1.equals("")) {
                            timerTask.cancel();
                            initDialog();
                            return;
                        }
                        if (imgurl2.equals("")) {
                            timerTask.cancel();
                            initDialog3();
                            return;
                        }
                        if (imgurl3.equals("")) {
                            timerTask.cancel();
                            initDialog4();
                            return;
                        }
                        if (imgurl4.equals("")) {
                            timerTask.cancel();
                            initDialog5();
                            return;
                        }
                        if (imgurl5.equals("")) {
                            timerTask.cancel();
                            initDialog6();
                            return;
                        }
                        String firsttime = sp2.getString("firsttime", "");//第一次抓拍时间
                        String numsecondpartstr = sp2.getString("numsecondpartstr", "");//第二次抓拍时间
                        String numthirdpartstr = sp2.getString("numthirdpartstr", "");//第三次抓拍时间
                        String numfourpartstr = sp2.getString("numfourpartstr", "");//第四次抓拍时间
                        String numFifthpartstr = sp2.getString("numFifthpartstr", "");//第五次抓拍时间
                        String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numthirdpartstr1 = numthirdpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numfourpartstr1 = numfourpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                        UserTcPhoto userTcPhoto = new UserTcPhoto();
                        userTcPhoto.setUrl(imgurl1);
                        userTcPhoto.setSnapTime(firsttimesub);
                        UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                        userTcPhoto1.setUrl(imgurl2);
                        userTcPhoto1.setSnapTime(numsecondpartstr1);
                        UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                        userTcPhoto2.setUrl(imgurl3);
                        userTcPhoto2.setSnapTime(numthirdpartstr1);
                        UserTcPhoto userTcPhoto3 = new UserTcPhoto();
                        userTcPhoto3.setUrl(imgurl4);
                        userTcPhoto3.setSnapTime(numfourpartstr1);
                        UserTcPhoto userTcPhoto4 = new UserTcPhoto();
                        userTcPhoto4.setUrl(imgurl5);
                        userTcPhoto4.setSnapTime(numFifthpartstr1);
                        photoList.add(userTcPhoto);
                        photoList.add(userTcPhoto1);
                        photoList.add(userTcPhoto2);
                        photoList.add(userTcPhoto3);
                        photoList.add(userTcPhoto4);
                        Gson gson = new Gson();
                        String strphotoList = gson.toJson(photoList);
                        LogUtils.e("strphotoList", strphotoList);
                        mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                        mProgressDialog.setMessage("提交中...");
                        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        mProgressDialog.setCancelable(false);
                        mProgressDialog.show();
                        new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength, 1, photoList, this, 3);
                    }


                }

            }
        } else if (id == R.id.img_course1) {
            if (!isloob) {
                img_course.setText("展开照片");
                totalle_course.setVisibility(View.GONE);
                img_course2.setImageResource(R.mipmap.down3);
                //  re_course1.setVisibility(View.GONE);
                isloob = true;
            } else {
                img_course.setText("收起照片");
                totalle_course.setVisibility(View.VISIBLE);
                img_course2.setImageResource(R.mipmap.top3);
                //   re_course1.setVisibility(View.VISIBLE);
                isloob = false;
            }
        }
    }

    //离开保存
    private void initsavedata(String userId, String orgId, int tcsn, int learnsn, int readLength, List<UserTcPhoto> photoList) {
        mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
        mProgressDialog.setMessage("离开保存...");
        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        mProgressDialog.setCancelable(false);
        mProgressDialog.show();
        new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, readLength, 0, photoList, this, 4);
    }

    //自动提交
    private void initsuredata(String userId, String orgId, int tcsn, int learnsn, int courseLength, List<UserTcPhoto> photoList) {
        mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
        mProgressDialog.setMessage("自动提交中...");
        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        mProgressDialog.setCancelable(false);
        mProgressDialog.show();
        new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength, 1, photoList, this, 3);
    }

    private String getNumTime(int cnt) {
        int hour = cnt / 3600;
        int min = cnt % 3600 / 60;
        int second = cnt % 60;
        if (hour == 0) {
            return String.format(Locale.CHINA, "%02d分%02d秒", min, second);
        } else {
            return String.format(Locale.CHINA, "%02d小时%02d分%02d秒", hour, min, second);
        }
    }

    @Override
    public void initData() {
        web = (WebView) findViewById(R.id.wb_course);
        le_parement = (LinearLayout) findViewById(R.id.le_couse);
        img_Courseback = (ImageView) findViewById(R.id.img_Courseback);
        img_course2 = (ImageView) findViewById(R.id.img_course2);
        lv_coursedetail = (RecyclerView) findViewById(R.id.lv_coursedetail);
        jcVideoPlayerStandard = (MyJZVideoPlayerStandard) findViewById(R.id.videoplayer);
        tv_courseName = (TextView) findViewById(R.id.tv_course);
        tv_courseLength = (TextView) findViewById(R.id.tv_course2);
        tv_course11 = (TextView)findViewById(R.id.tv_course11);
        tv_cumulativeLength = (TextView)findViewById(R.id.tv_course3);
        show_camera_iv = (ImageView)findViewById(R.id.id_show_camera_iv);
        show_camera_iv1 = (ImageView)findViewById(R.id.id_show_camera_iv1);
        show_camera_iv2 = (ImageView)findViewById(R.id.id_show_camera_iv2);
        show_camera_iv3 = (ImageView)findViewById(R.id.id_show_camera_iv3);
        show_camera_iv4 = (ImageView)findViewById(R.id.id_show_camera_iv4);
        surfaceSv = (SurfaceView)findViewById(R.id.id_area_sv);
        tv_sure = (TextView) findViewById(R.id.tv_course10);
        re_course = (RelativeLayout)findViewById(R.id.re_course);
        totalle_course = (LinearLayout)findViewById(R.id.totalle_course);
        re_course1 = (LinearLayout)findViewById(R.id.le_course1);
        img_course = (TextView) findViewById(R.id.img_course1);
        tv_course12 = (TextView) findViewById(R.id.tv_course12);
        re_course2 = (RelativeLayout)findViewById(R.id.re_course2);
        playOrPauseFab = (ImageView)findViewById(R.id.img_playorpause);
        tv_playorpause = (TextView)findViewById(R.id.tv_playorpause);
        progress_tv = (TextView)findViewById(R.id.progress_tv);
        total_tv = (TextView)findViewById(R.id.total_tv);
        mSuperFileView = (SuperFileView2) findViewById(R.id.mSuperFileView);
        musicSeekBar=(SeekBar)findViewById(R.id.music_seekbar);

        StatusBarCompat.setStatusBarColor(this, Color.parseColor("#1F80C4"));
        musicHandler = new MusicHandler();
        web.setHorizontalScrollBarEnabled(false);//水平不显示
        web.setVerticalScrollBarEnabled(false); //垂直不显示
        web.setWebViewClient(new WebViewClient() {
            /*
            此处能拦截超链接的url,即拦截href请求的内容。
            */
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                return true;
            }
        });
        //注册EventBus
        EventBus.getDefault().register(this);
        sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
        sensorEventListener = new Jzvd.JZAutoFullscreenListener();
        Sensor accelerometerSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
        sensorManager.registerListener(sensorEventListener, accelerometerSensor, SensorManager.SENSOR_DELAY_NORMAL);

        timer1 = new Timer();
        firsttime = (int) (20 + Math.random() * (30 - 20 + 1));//第一次拍照随机20秒到30秒
        //第二次验证拍照一分钟之后随机20秒到30秒
        firsttime1 = (int) (80 + Math.random() * (30 - 20 + 1));
        Bundle bundle = getIntent().getExtras();
        //通过name关键字取出用户名
        int tcsn = bundle.getInt("tcsn");
        //     readInterval = bundle.getInt("readInterval");
        minPer = bundle.getInt("minPer");
        String orgId = bundle.getString("orgId");
        setYm = bundle.getString("setYm");
        photoMark = bundle.getInt("photoMark");
        signMark = bundle.getInt("signMark");
        int learnsn = bundle.getInt("learnsn");
        int faceRecgMark = bundle.getInt("faceRecgMark");
        int qpSn = bundle.getInt("qpSn");
        String photoUrl = bundle.getString("photoUrl");
        SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                Context.MODE_PRIVATE);
        SharedPreferences.Editor edit = sp.edit();
        edit.putString("orgId", orgId);
        edit.putInt("learnsn", learnsn);
        edit.putInt("tcsn", tcsn);
        edit.putString("photoUrl", photoUrl);
        edit.putInt("faceRecgMark", faceRecgMark);
        edit.putInt("qpSn", qpSn);
        edit.commit();


        if (photoMark == 1) {
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
                    mHandler.sendEmptyMessage(0);
                }
            });
            thread.start();
        } else if (photoMark == 0) {
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
                    mHandler.sendEmptyMessage(2);
                }
            });
            thread.start();
        } else if (photoMark == 2) {
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
                    mHandler.sendEmptyMessage(3);
                }
            });
            thread.start();
        } else if (photoMark == 3) {
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
                    mHandler.sendEmptyMessage(4);
                }
            });
            thread.start();
        } else if (photoMark == 4) {
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
                    mHandler.sendEmptyMessage(5);
                }
            });
            thread.start();
        } else if (photoMark == 5) {
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
                    mHandler.sendEmptyMessage(6);
                }
            });
            thread.start();
        }


//        Thread thread1 = new Thread(new Runnable() {
//            @Override
//            public void run() {
//                //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
//                mHandler.sendEmptyMessage(1);
//            }
//        });
//        thread1.start();


        //摄像头
        int cameraCount = 1;
        Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
        cameraCount = Camera.getNumberOfCameras();// 得到摄像头的个数

        for (int i = 0; i < cameraCount; i++) {
            Camera.getCameraInfo(i, cameraInfo);// 得到每一个摄像头的信息
            // 现在是后置，变更为前置
            if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
                /**
                 * 记得释放camera，方便其他应用调用
                 */
                releaseCamera();
                // 打开当前选中的摄像头
                mCamera = Camera.open(i);
                //   mCamera.setDisplayOrientation(90);//旋转度数
                // 通过surfaceview显示取景画面
                setStartPreview(mCamera, mHolder);

            }
        }
        // 获得句柄
        mHolder = surfaceSv.getHolder();
        // 添加回调
        mHolder.addCallback(this);
        initSeekba();//语音播放ui

    }

    private void initSeekba() {

        musicSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                int musicDuration = mediaPlayer.getDuration();
                if (musicDuration == -1) return;

                if (musicDuration < 0) {
                    progress_tv.setText(MusicUtils.getTime(0));
                    total_tv.setText(MusicUtils.getTime(0));
                } else {
                    progress_tv.setText(MusicUtils.getTime(progress));
                    total_tv.setText(MusicUtils.getTime(musicDuration));
                }
                //  LogUtils.e("musicSeekBar",musicDuration+"");

            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                int musicDuration = mediaPlayer.getDuration();
                if (musicDuration == -1) return;
                int progress = seekBar.getProgress();
                mediaPlayer.seekTo(progress);
                mediaPlayer.start();
                progress_tv.setText(MusicUtils.getTime(progress));
                total_tv.setText(MusicUtils.getTime(musicDuration));
            }
        });


        initMusicPlayer();
    }

    public void initMusicPlayer() {
        musicPrepared();
        mediaPlayer.setOnCompletionListener(this);
        mediaPlayer.setOnErrorListener(this);

    }

    public void toggle() {
        if (tv_playorpause.getText().toString().trim().equals("播放")) {
            pause();
        } else if (tv_playorpause.getText().toString().trim().equals("暂停")) {
            start();
        }
    }

    public void start() {
        //     musicPrepared();
        mediaPlayer.start();
        musicHandler.sendEmptyMessage(0);
        playOrPauseFab.setImageResource(R.mipmap.play);
        tv_playorpause.setText("播放");
        //  isPlaying = true;

    }

    public void pause() {
        mediaPlayer.pause();
        musicHandler.removeMessages(0);
        playOrPauseFab.setImageResource(R.mipmap.stop);
        tv_playorpause.setText("暂停");
        //   isPlaying = false;
        //   fmm.stop();
    }

    private void updateProgress() {
        int musicDuration = mediaPlayer.getDuration();
        LogUtils.e("musicDuration", musicDuration + "");
        if (musicDuration == -1) return;
        int musicProgress = mediaPlayer.getCurrentPosition();
        musicSeekBar.setProgress(musicProgress);
        musicSeekBar.setMax(musicDuration);
        //     fmm.setProgress(musicProgress * 100 / musicDuration);
    }

    private void musicPrepared() {
        try {
            //   AssetFileDescriptor afd = getAssets().openFd("99nights.mp3");
            if (mediaPlayer != null) {
                mediaPlayer.reset();
                mediaPlayer = null;
            }
            mediaPlayer = new MediaPlayer();
            mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
            SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                    Context.MODE_PRIVATE);
            String accessAudioUrl = sp.getString("accessAudioUrl", "");
            if (accessAudioUrl.equals("")) {
                // showToast("语音文件是空");
                return;
            }
            Uri uri = Uri.parse(accessAudioUrl);
            mediaPlayer.setDataSource(CourseDetailsActivity.this, uri);
            mediaPlayer.prepareAsync();
            mediaPlayer.setOnPreparedListener(this);

            musicHandler.sendEmptyMessage(0);
            playOrPauseFab.setImageResource(R.mipmap.play);
            tv_playorpause.setText("播放");
//            int duration = mediaPlayer.getDuration();
//            total_tv.setText(MusicUtils.getTime(duration));//刚开始获取时长
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onCompletion(MediaPlayer mp) {
        complete(mp);
    }

    public void complete(MediaPlayer mp) {
        //   isPlaying = false;
        mp.stop();
        musicHandler.removeMessages(0);
        playOrPauseFab.setImageResource(R.mipmap.stop);
        tv_playorpause.setText("暂停");
//        fmm.stop();
//        fmm.setProgress(100);
        musicPrepared();
    }

    @Override
    public void onPrepared(MediaPlayer mp) {
        mp.start();
    }

    @Override
    public boolean onError(MediaPlayer mp, int what, int extra) {
        LogUtils.e("MMP", "Media player error: what=" + what + ", extra=" + extra);
        return false;
    }

    public class MusicHandler extends Handler {

        @Override
        public void dispatchMessage(Message msg) {
            super.dispatchMessage(msg);
            updateProgress();
            sendEmptyMessageDelayed(0, 1000);
        }
    }

    @Override
    public void onFailure(Call call, int what) {
        super.onFailure(call, what);
        if (what == 3) {
            mProgressDialog.dismiss();
            Toast.makeText(CourseDetailsActivity.this, "提交失败，重新提交", Toast.LENGTH_LONG).show();
        } else if (what == 4) {
            mProgressDialog.dismiss();
            Toast.makeText(CourseDetailsActivity.this, "保存失败，重新保存", Toast.LENGTH_LONG).show();
        }

    }


    @Override
    public void onSuccess(String result, Call call, Response response, int what) {
        if (what == 3) {
            SignBean signBean = JSON.parseObject(result, SignBean.class);
            final SignBean.DataBean data = signBean.getData();
            if (data.getFinishMark() == 0)//未完成
            {
                //   int coursePointNo = data.getCoursePointNo();
                mProgressDialog.dismiss();
                timerTask.cancel();
                timer1.cancel();
                timerTask = null;
                timer1 = null;
                SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                        Context.MODE_PRIVATE);
                SharedPreferences.Editor edit = sp.edit();
                edit.clear();
                edit.commit();
                finish();
                showToast("该课程提交成功");
//           AlertDialog.Builder builder = new AlertDialog.Builder(this);
//           View view = View
//                   .inflate(CourseDetailsActivity.this, R.layout.diolog_learn_layout, null);
//           TextView tv_message= (TextView) view
//                   .findViewById(R.id.message);//输入内容
//           tv_message.setText("恭喜您!本课程学习完获得"+coursePointNo+"积分");
//           TextView btn_sure = (TextView) view.findViewById(R.id.positiveButton);
//           TextView btn_cancel = (TextView) view.findViewById(R.id.negativeButton);
//           btn_cancel.setVisibility(View.GONE);
//           btn_sure.setText("确定");
//           final    AlertDialog dialog = builder.create();
//           dialog.show();
//           dialog.getWindow().setContentView(view);
//           dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
//           dialog.setCancelable(false);
//           btn_sure.setOnClickListener(new View.OnClickListener() {
//               @Override
//               public void onClick(View view) {
//                   dialog.dismiss();
//
//               }
//           });
            } else if (data.getFinishMark() == 1)//已完成未签名
            {
                mProgressDialog.dismiss();
                if (signMark >= 1) {

                    timerTask.cancel();
                    timer1.cancel();
                    timerTask = null;
                    timer1 = null;
//               if(coursePointNo>0&&chPointNo>0) {
//                   AlertDialog.Builder builder = new AlertDialog.Builder(this);
//                   View view = View
//                           .inflate(CourseDetailsActivity.this, R.layout.diolog_learn_layout, null);
//                   TextView tv_message = (TextView) view
//                           .findViewById(R.id.message);//输入内容
//                   tv_message.setText("恭喜您!本课程学习完获得" + coursePointNo + "积分,本月学时任务已完成。恭喜额外获得" + chPointNo + "积分");
//                   TextView btn_sure = (TextView) view.findViewById(R.id.positiveButton);
//                   TextView btn_cancel = (TextView) view.findViewById(R.id.negativeButton);
//                   btn_cancel.setVisibility(View.GONE);
//                   btn_sure.setText("确定");
//                   final AlertDialog dialog = builder.create();
//                   dialog.show();
//                   dialog.getWindow().setContentView(view);
//                   dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
//                   dialog.setCancelable(false);
//                   btn_sure.setOnClickListener(new View.OnClickListener() {
//                       @Override
//                       public void onClick(View view) {
//                           dialog.dismiss();
//                           SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
//                                   Context.MODE_PRIVATE);
//                           int learnsn = sp.getInt("learnsn", 0);
//                           Bundle bundle = new Bundle();
//                           bundle.putInt("sn", learnsn);
//                           bundle.putString("signPicUrl", "");
//                           startActivity(SignActivity.class, bundle);
//                           finish();
//                           showToast("该课程提交成功");
//                           SharedPreferences.Editor edit = sp.edit();
//                           edit.clear();
//                           edit.commit();
//                       }
//                   });
//               }else{
                    SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                            Context.MODE_PRIVATE);
                    int learnsn = sp.getInt("learnsn", 0);
                    Bundle bundle = new Bundle();
                    bundle.putInt("sn", learnsn);
                    bundle.putString("signPicUrl", "");
                    bundle.putInt("signMark", signMark);
                    startActivity(SignActivity.class, bundle);
                    finish();
                    showToast("该课程提交成功");
                    SharedPreferences.Editor edit = sp.edit();
                    edit.clear();
                    edit.commit();

                } else if (signMark == 0)//不需要签名
                {
                    timerTask.cancel();
                    timer1.cancel();
                    timerTask = null;
                    timer1 = null;
//               if(coursePointNo>0&&chPointNo==0) {
//                   AlertDialog.Builder builder = new AlertDialog.Builder(this);
//                   View view = View
//                           .inflate(CourseDetailsActivity.this, R.layout.diolog_learn_layout, null);
//                   TextView tv_message = (TextView) view
//                           .findViewById(R.id.message);//输入内容
//                   tv_message.setText("恭喜您!本课程学习完获得" + coursePointNo + "积分,本月学时任务已完成。恭喜额外获得" + chPointNo + "积分");
//                   TextView btn_sure = (TextView) view.findViewById(R.id.positiveButton);
//                   TextView btn_cancel = (TextView) view.findViewById(R.id.negativeButton);
//                   btn_cancel.setVisibility(View.GONE);
//                   btn_sure.setText("确定");
//                   final AlertDialog dialog = builder.create();
//                   dialog.show();
//                   dialog.getWindow().setContentView(view);
//                   dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
//                   dialog.setCancelable(false);
//                   btn_sure.setOnClickListener(new View.OnClickListener() {
//                       @Override
//                       public void onClick(View view) {
//                           dialog.dismiss();
//                           SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
//                                   Context.MODE_PRIVATE);
//                           SharedPreferences.Editor edit = sp.edit();
//                           edit.clear();
//                           edit.commit();
//                           finish();
//                           showToast("该课程提交成功");
//                       }
//                   });
//               }else{
                    SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                            Context.MODE_PRIVATE);
                    SharedPreferences.Editor edit = sp.edit();
                    edit.clear();
                    edit.commit();
                    finish();
                    showToast("该课程提交成功");

                }

            } else if (data.getFinishMark() == 2) {
                mProgressDialog.dismiss();
                timerTask.cancel();
                timer1.cancel();
                timerTask = null;
                timer1 = null;
//           if(chPointNo>0&&coursePointNo>0)
//           {
//               AlertDialog.Builder builder = new AlertDialog.Builder(this);
//               View view = View
//                       .inflate(CourseDetailsActivity.this, R.layout.diolog_learn_layout, null);
//               TextView tv_message= (TextView) view
//                       .findViewById(R.id.message);//输入内容
//               tv_message.setText("恭喜您!本课程学习完获得"+coursePointNo+"积分,本月学时任务已完成。恭喜额外获得"+chPointNo+"积分");
//               TextView btn_sure = (TextView) view.findViewById(R.id.positiveButton);
//               TextView btn_cancel = (TextView) view.findViewById(R.id.negativeButton);
//               btn_cancel.setVisibility(View.GONE);
//               btn_sure.setText("确定");
//               final    AlertDialog dialog = builder.create();
//               dialog.show();
//               dialog.getWindow().setContentView(view);
//               dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
//               dialog.setCancelable(false);
//               btn_sure.setOnClickListener(new View.OnClickListener() {
//                   @Override
//                   public void onClick(View view) {
//                       dialog.dismiss();
//                       SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
//                               Context.MODE_PRIVATE);
//                       SharedPreferences.Editor edit = sp.edit();
//                       edit.clear();
//                       edit.commit();
//                       finish();
//                       showToast("该课程提交成功");
//                   }
//               });
//           }else if(coursePointNo>0&&chPointNo==0){
//
//               AlertDialog.Builder builder = new AlertDialog.Builder(this);
//               View view = View
//                       .inflate(CourseDetailsActivity.this, R.layout.diolog_learn_layout, null);
//               TextView tv_message= (TextView) view
//                       .findViewById(R.id.message);//输入内容
//               tv_message.setText("恭喜您!本课程学习完获得"+coursePointNo+"积分");
//               TextView btn_sure = (TextView) view.findViewById(R.id.positiveButton);
//               TextView btn_cancel = (TextView) view.findViewById(R.id.negativeButton);
//               btn_cancel.setVisibility(View.GONE);
//               btn_sure.setText("确定");
//               final    AlertDialog dialog = builder.create();
//               dialog.show();
//               dialog.getWindow().setContentView(view);
//               dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
//               dialog.setCancelable(false);
//               btn_sure.setOnClickListener(new View.OnClickListener() {
//                   @Override
//                   public void onClick(View view) {
//                       dialog.dismiss();
//                       SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
//                               Context.MODE_PRIVATE);
//                       SharedPreferences.Editor edit = sp.edit();
//                       edit.clear();
//                       edit.commit();
//                       finish();
//                       showToast("该课程提交成功");
//                   }
//               });
//
//           }else if(coursePointNo==0&&chPointNo>0)
//           {
//               AlertDialog.Builder builder = new AlertDialog.Builder(this);
//               View view = View
//                       .inflate(CourseDetailsActivity.this, R.layout.diolog_learn_layout, null);
//               TextView tv_message= (TextView) view
//                       .findViewById(R.id.message);//输入内容
//               tv_message.setText("恭喜您!本月学时任务已完成。恭喜额外获得"+chPointNo+"积分");
//               TextView btn_sure = (TextView) view.findViewById(R.id.positiveButton);
//               TextView btn_cancel = (TextView) view.findViewById(R.id.negativeButton);
//               btn_cancel.setVisibility(View.GONE);
//               btn_sure.setText("确定");
//               final    AlertDialog dialog = builder.create();
//               dialog.show();
//               dialog.getWindow().setContentView(view);
//               dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
//               dialog.setCancelable(false);
//               btn_sure.setOnClickListener(new View.OnClickListener() {
//                   @Override
//                   public void onClick(View view) {
//                       dialog.dismiss();
//                       SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
//                               Context.MODE_PRIVATE);
//                       SharedPreferences.Editor edit = sp.edit();
//                       edit.clear();
//                       edit.commit();
//                       finish();
//                       showToast("该课程提交成功");
//                   }
//               });
//           }else{
                SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                        Context.MODE_PRIVATE);
                SharedPreferences.Editor edit = sp.edit();
                edit.clear();
                edit.commit();
                finish();
                showToast("该课程提交成功");
            } else if (data.getFinishMark() == 3) {
                mProgressDialog.dismiss();
                timerTask.cancel();
                timer1.cancel();
                timerTask = null;
                timer1 = null;

                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                View view = View
                        .inflate(CourseDetailsActivity.this, R.layout.diolog_learn_layout, null);
                TextView tv_message = (TextView) view
                        .findViewById(R.id.message);//输入内容
                tv_message.setText("您已完成本月学习，是否进行考试？");
                TextView btn_sure = (TextView) view.findViewById(R.id.positiveButton);
                TextView btn_cancel = (TextView) view.findViewById(R.id.negativeButton);
                btn_sure.setText("去考试");
                btn_cancel.setText("离开");
                final AlertDialog dialog = builder.create();
                dialog.show();
                dialog.getWindow().setContentView(view);
                dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                dialog.setCancelable(false);
                btn_sure.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        dialog.dismiss();
                        SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                                Context.MODE_PRIVATE);
                        String orgId = sp.getString("orgId", "");
                        int learnsn = sp.getInt("learnsn", 0);
                        int qpSn = sp.getInt("qpSn", 0);
                        int faceRecgMark = sp.getInt("faceRecgMark", 0);
                        String photoUrl = sp.getString("photoUrl", "");
                        Bundle bundle = new Bundle();
                        bundle.putString("orgId", orgId);
                        bundle.putInt("qpSn", qpSn);
                        bundle.putInt("learnsn", learnsn);
                        bundle.putInt("faceRecgMark", faceRecgMark);
                        bundle.putString("photoUrl", photoUrl);
                        startActivity(DailyTrainingExaminationItemActivity.class, bundle);
                        finish();
                        showToast("该课程提交成功");
                        SharedPreferences.Editor edit = sp.edit();
                        edit.clear();
                        edit.commit();

                    }
                });
                btn_cancel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {//跳回学时界面
                        dialog.dismiss();
                        SharedPreferences sp = getSharedPreferences("homefgt", Context.MODE_PRIVATE);
                        String orgName = sp.getString("orgName", "");
                        String orgId = sp.getString("orgId", "");
                        String forbidHour = sp.getString("forbidHour", "");
                        int minPer = sp.getInt("minPer", 0);
                        int readInterval = sp.getInt("readInterval", 0);
                        int Mark = sp.getInt("Mark", 0);
                        int signMark1 = sp.getInt("signMark", 0);
                        int photoMark = sp.getInt("photoMark", 0);
                        int faceRecgMark = sp.getInt("faceRecgMark", 0);
                        int feeType = sp.getInt("feeType", 0);
                        String photoUrl = sp.getString("personphotoUrl", "");
                        int mtSeqMark = sp.getInt("mtSeqMark", 0);
                        int allowMuT = sp.getInt("allowMuT", 0);
                        if (faceRecgMark == 1 || faceRecgMark == 2) {
                            Bundle bundle1 = new Bundle();
                            bundle1.putInt("minPer", minPer);
                            bundle1.putInt("readInterval", readInterval);
                            bundle1.putInt("signMark", signMark1);
                            bundle1.putInt("Mark", Mark);
                            bundle1.putString("orgId", orgId);
                            bundle1.putString("forbidHour", forbidHour);
                            bundle1.putInt("photoMark", photoMark);
                            bundle1.putInt("faceRecgMark", faceRecgMark);
                            bundle1.putString("personphotoUrl", photoUrl);
                            bundle1.putInt("feeType", feeType);
                            bundle1.putString("orgName", orgName);
                            bundle1.putInt("mtSeqMark", mtSeqMark);
                            bundle1.putInt("allowMuT", allowMuT);
                            startActivity(SpecifiedLearningHomeActivity.class, bundle1);
                            finish();
                        } else if (faceRecgMark == 0) {
                            Bundle bundle1 = new Bundle();
                            bundle1.putInt("minPer", minPer);
                            bundle1.putInt("readInterval", readInterval);
                            bundle1.putInt("signMark", signMark1);
                            bundle1.putInt("Mark", Mark);
                            bundle1.putString("orgId", orgId);
                            bundle1.putString("forbidHour", forbidHour);
                            bundle1.putInt("photoMark", photoMark);
                            bundle1.putInt("faceRecgMark", 0);
                            bundle1.putString("personphotoUrl", "");
                            bundle1.putInt("feeType", feeType);
                            bundle1.putString("orgName", orgName);
                            bundle1.putInt("mtSeqMark", mtSeqMark);
                            bundle1.putInt("allowMuT", allowMuT);
                            startActivity(SpecifiedLearningHomeActivity.class, bundle1);
                            finish();
                        }

                    }
                });
            }
        }
        if (what == 4) {

            SharedPreferences sp1 = getSharedPreferences("CourseDetailsActivity",
                    Context.MODE_PRIVATE);
            SharedPreferences.Editor edit = sp1.edit();
            edit.clear();
            edit.commit();
            mProgressDialog.dismiss();
            timerTask.cancel();
            timer1.cancel();
            timerTask = null;
            timer1 = null;
            finish();
        }

        super.onSuccess(result, call, response, what);
    }

    @Override
    public void onError(String result, Call call, Response response, int what) {
        if (what == 3) {
            mProgressDialog.dismiss();
            CheckBean checkBean = JSON.parseObject(result, CheckBean.class);
            //     int code = checkBean.getCode();
            String msg = checkBean.getMsg();
            TiShiDialog.Builder builder1 = new TiShiDialog.Builder(this);
            builder1.setMessage(msg);
            builder1.setTitle("提示:");
            builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    ;
                    //设置你的操作事项
                }
            });
            builder1.create().show();

        }

        super.onError(result, call, response, what);
    }

    @Override
    public void requestData() {
        initcourseData();
        initcoursesubject();
//        ModyPhotoUrl();//查询移动端是否可以上传头像

    }

    //    private void ModyPhotoUrl() {
//        LoginUserBean userInfo = UserManger.getUserInfo();
//        LoginUserBean.DataBean data = userInfo.getData();
//        String userId = data.getUserId();
//        RequestParams params = new RequestParams(AppInterfaceConfig.BASE_URL + "sys/orgExtraFunction/findMobileFuMark/" + userId);
//        x.http().get(params, new org.xutils.common.Callback.CommonCallback<String>() {
//            @Override
//            public void onSuccess(String result) {
//                CheckBean checkBean = JSON.parseObject(result, CheckBean.class);
//                Integer checkBeanData = checkBean.getData();
//                SharedPreferences sp= getSharedPreferences("CourseDetailsActivity", Context.MODE_PRIVATE);
//                SharedPreferences.Editor edit = sp.edit();
//                edit.putInt("checkphoto",checkBeanData);
//                edit.commit();
//            }
//
//            @Override
//            public void onError(Throwable ex, boolean isOnCallback) {
//                showToast("网络连接错误");
//            }
//
//            @Override
//            public void onCancelled(CancelledException cex) {
//
//            }
//
//            @Override
//            public void onFinished() {
//
//            }
//        });
//
//
//    }
    //根据课程序列号查询测验题
    private void initcoursesubject() {
        SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                Context.MODE_PRIVATE);
        int tcsn = sp.getInt("tcsn", 0);
        RequestParams params = new RequestParams(AppInterfaceConfig.BASE_URL + "course/question/" + tcsn);
        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                CourseDetailSubjectBean courseDetailSubjectBean = JSON.parseObject(result, CourseDetailSubjectBean.class);
                rowsList = courseDetailSubjectBean.getRows();
                if (rowsList.size() == 0) {
                    tv_course11.setVisibility(View.GONE);
                    return;
                }
                tv_course11.setVisibility(View.VISIBLE);

                RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(CourseDetailsActivity.this);
                lv_coursedetail.setLayoutManager(layoutManager);
                courseDetailSubjectApt = new CourseDetailRvSubjectApt(CourseDetailsActivity.this, rowsList);
                lv_coursedetail.setAdapter(courseDetailSubjectApt);
               /* courseDetailSubjectApt = new CourseDetailSubjectApt(CourseDetailsActivity.this, rowsList, R.layout.course_detail_item);
                lv_coursedetail.setAdapter(courseDetailSubjectApt);*/
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                showToast("网络连接错误");
            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });

//        OkGo.get(AppInterfaceConfig.BASE_URL + "course/question/" + tcsn)     // 请求方式和请求url
//                .tag(this)                       // 请求的 tag, 主要用于取消对应的请求
//                .execute(new StringCallback() {
//                    @Override
//                    public void onSuccess(String result, Call call, Response response) {
//                        CourseDetailSubjectBean courseDetailSubjectBean = JSON.parseObject(result, CourseDetailSubjectBean.class);
//                        rowsList = courseDetailSubjectBean.getRows();
//                        if(rowsList.size()==0)
//                        {
//                            tv_course11.setVisibility(View.GONE);
//                            return;
//                        }
//                        tv_course11.setVisibility(View.VISIBLE);
//                        courseDetailSubjectApt = new CourseDetailSubjectApt(CourseDetailsActivity.this, rowsList, R.layout.course_detail_item);
//                        lv_coursedetail.setAdapter(courseDetailSubjectApt);
//                    }
//
//                    @Override
//                    public void onError(Call call, Response response, Exception e) {
//                        super.onError(call, response, e);
//                        showToast("网络连接错误");
//                    }
//                });
    }

    //根据课程序列号查询课程详情
    private void initcourseData() {
        SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                Context.MODE_PRIVATE);
        int tcsn = sp.getInt("tcsn", 0);
        RequestParams params = new RequestParams(AppInterfaceConfig.BASE_URL + "course/course/" + tcsn);
        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                CourseDetailBean courseDetailBean = JSON.parseObject(result, CourseDetailBean.class);
                CourseDetailBean.DataBean coursedata = courseDetailBean.getData();
                String courseName = coursedata.getCourseName();//课程名称

                if (courseName != null) {
                    tv_courseName.setText(courseName);
                }
                //课程时长
                int courseLength = coursedata.getCourseLength();


                //课长判断何久拍照
                tv_courseLength.setText("课程时长:" + courseLength + "分钟");

                //视频地址
                String accessVideoUrl = coursedata.getAccessVideoUrl();
                video(accessVideoUrl);
                //音频地址
                String accessAudioUrl = coursedata.getAccessAudioUrl();
                Audio(accessAudioUrl);
                photo(courseLength);

                //PDF文件解析
                String fileUrl = coursedata.getFileUrl();
                String fileName = coursedata.getFileName();
                if (fileUrl != null) {
                    mSuperFileView.setVisibility(View.VISIBLE);
                    mSuperFileView.setOnGetFilePathListener(new SuperFileView2.OnGetFilePathListener() {
                        @Override
                        public void onGetFilePath(SuperFileView2 mSuperFileView2) {
                            String path = FileParseUtil.getFilePath(mSuperFileView2, fileUrl, fileName);
                            if (path.contains("http")) {//网络地址要先下载
                                showAlertDialog(mSuperFileView2, fileUrl);
                            } else {
                                mSuperFileView2.displayFile(new File(path));
                            }
                        }
                    });
                    mSuperFileView.show();
                }

                String courseContent = coursedata.getCourseContent();
                if (courseContent != null) {
                    new Thread(new runn(courseContent)).start();
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                showToast("网络连接错误");
            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    private String getNewContent(String htmltext) {
        Document doc = Jsoup.parse(htmltext);
        Elements elements = doc.getElementsByTag("img");
        for (Element element : elements) {
            element.attr("width", "100%").attr("height", "auto");
        }

        return doc.toString();
    }

    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            Bundle data = msg.getData();
            String val = data.getString("value");
            String html = "<html><body>" + val + "</body></html>";
            web.loadDataWithBaseURL(null,
                    getNewContent(html), "text/html", "utf-8",
                    null);
        }
    };

    /**
     * 网络操作相关的子线程
     */
    public class runn implements Runnable {
        String vv;

        public runn(String vv) {
            this.vv = vv;
        }

        @Override
        public void run() {
            Message msg = new Message();
            Bundle data = new Bundle();
            data.putString("value", vv);
            msg.setData(data);
            handler.sendMessage(msg);
        }
    }


    private void Audio(String accessAudioUrl) {

        if (accessAudioUrl == null) {
            re_course2.setVisibility(View.GONE);

            return;
        }
        re_course2.setVisibility(View.VISIBLE);
        SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putString("accessAudioUrl", accessAudioUrl);
        editor.commit();

    }


    private void photo(int courseLength) {
        //   LoginUserBean userInfo = UserManger.getUserInfo();
//        Integer minPer = userInfo.getData().getMinPer();//所属行政区划学习时长最低百分比
        //   int num = (courseLength * 60 * minPer) / 100;
//        Random rand = new Random();
//        int i = rand.nextInt(num);
//        int j = i + 1;
//        int j = (int) (num * 0.35 + Math.random() * (num * 0.45 - num * 0.35 + 1));//第二次拍照随机
//        TimeUtils timeUtils = new TimeUtils();
//        String duration = timeUtils.stringForTime(j * 1000);
        SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                Context.MODE_PRIVATE);
        //  SharedPreferences.Editor editor = sp.edit();
        //       editor.putString("duration", duration);
//        editor.putInt("num", num);
//        editor.putInt("courseLength", courseLength);
//        editor.commit();

        if (photoMark == 1) {
            int num = (courseLength * 60 * minPer) / 100;
            SharedPreferences.Editor editor = sp.edit();
            editor.putInt("num", num);
            editor.putInt("courseLength", courseLength);
            editor.commit();
        } else if (photoMark == 0) {
            int num = (courseLength * 60 * minPer) / 100;
            SharedPreferences.Editor editor = sp.edit();
            editor.putInt("num", num);
            editor.putInt("courseLength", courseLength);
            editor.commit();
        } else if (photoMark == 2) {
            int Fifthpart = 0;
            int num = (courseLength * 60 * minPer) / 100;
            int numFifthpart = (num * 4) / 5;//五分四提示拍照
            Fifthpart = (int) ((numFifthpart - 5) + Math.random() * 10);//最后一张上下五秒钟随机数
            SharedPreferences.Editor editor = sp.edit();
            editor.putInt("num", num);
            editor.putInt("numFifthpart", Fifthpart);
            editor.putInt("courseLength", courseLength);
            editor.commit();
        } else if (photoMark == 3) {
            int num = (courseLength * 60 * minPer) / 100;
            int secondpart = 0;
            int Fifthpart = 0;

            int numFifthpart = (num * 4) / 5;//五分四提示拍照
            Fifthpart = (int) ((numFifthpart - 5) + Math.random() * 10);//最后一张上下五秒钟随机数
            int numsecondpart = (num / 2);//30秒到五分之四时间点的二分之一提示拍照
            secondpart = (int) ((numsecondpart - 5) + Math.random() * 10);//第二张上下五秒钟随机数


//            int numFifthpart = (num * 4) / 5;//五分四提示拍照
//            int numsecondpart = 30+((numFifthpart-30)/2);//30秒到五分之四时间点的二分之一提示拍照
            SharedPreferences.Editor editor = sp.edit();
            editor.putInt("num", num);
            editor.putInt("numsecondpart", secondpart);
            editor.putInt("numFifthpart", Fifthpart);
            editor.putInt("courseLength", courseLength);
            editor.commit();
        } else if (photoMark == 4) {
            int secondpart = 0;
            int thirdpart = 0;
            int Fifthpart = 0;
            int num = (courseLength * 60 * minPer) / 100;
            int numFifthpart = (num * 4) / 5;//五分四提示拍照
            Fifthpart = (int) ((numFifthpart - 5) + Math.random() * 10);//最后一张上下五秒钟随机数
            int numsecondpart = num / 3;//30秒到五分之四时间点的三分之一提示拍照
            secondpart = (int) ((numsecondpart - 5) + Math.random() * 10);//第二张上下五秒钟随机数
            int numthirdpart = (num * 2) / 3;//30秒到五分之四时间点的三分之二提示拍照
            thirdpart = (int) ((numthirdpart - 5) + Math.random() * 10);//第三张上下五秒钟随机数
            SharedPreferences.Editor editor = sp.edit();
            editor.putInt("num", num);
            editor.putInt("numsecondpart", secondpart);
            editor.putInt("numthirdpart", thirdpart);
            editor.putInt("numFifthpart", Fifthpart);
            editor.putInt("courseLength", courseLength);
            editor.commit();
        } else if (photoMark == 5) {
            int secondpart = 0;
            int thirdpart = 0;
            int fourpart = 0;
            int Fifthpart = 0;
            int num = (courseLength * 60 * minPer) / 100;

            int numFifthpart = (num * 4) / 5;//五分四提示拍照
            Fifthpart = (int) ((numFifthpart - 5) + Math.random() * 10);//最后一张上下五秒钟随机数
            int numsecondpart = (num / 4);//30秒到五分之四时间点的四分之一提示拍照
            secondpart = (int) ((numsecondpart - 5) + Math.random() * 10);//第二张上下五秒钟随机数
            int numthirdpart = (num / 2);//30秒到五分之四时间点的二分之二提示拍照
            thirdpart = (int) ((numthirdpart - 5) + Math.random() * 10);//第三张上下五秒钟随机数
            int numfourpart = (num * 3) / 4;//30秒到五分之四时间点的四分之三提示拍照
            fourpart = (int) ((numfourpart - 5) + Math.random() * 10);//第四张上下五秒钟随机数
            SharedPreferences.Editor editor = sp.edit();
            editor.putInt("num", num);
            editor.putInt("numsecondpart", secondpart);
            editor.putInt("numthirdpart", thirdpart);
            editor.putInt("numfourpart", fourpart);
            editor.putInt("numFifthpart", Fifthpart);
            editor.putInt("courseLength", courseLength);
            editor.commit();
        }


    }

    private void video(String accessVideoUrl) {
        if (accessVideoUrl == null) {
            jcVideoPlayerStandard.setVisibility(View.GONE);
            return;
        }
        jcVideoPlayerStandard.setVisibility(View.VISIBLE);
        HashMap headers = new HashMap<String, String>();
        headers.put("Referer",AppInterfaceConfig.BASE_URL);
        JZDataSource jzDataSource=new JZDataSource(accessVideoUrl,"",headers);
        jcVideoPlayerStandard.setUp(jzDataSource,jcVideoPlayerStandard.SCREEN_NORMAL);
        //jcVideoPlayerStandard.setUp(accessVideoUrl, "", jcVideoPlayerStandard.SCREEN_NORMAL, JZMediaIjk.class);
//        jcVideoPlayerStandard.loop  = true;//是否循环播放
        //      jcVideoPlayerStandard.startVideo();//自动播放
        Picasso.with(getApplicationContext()).load(R.mipmap.video)
                .into(jcVideoPlayerStandard.thumbImageView);
        JzvdStd.progressBar.setEnabled(false);//禁止拖动
    }


    @SuppressLint("HandlerLeak")
    private void initDialog() {
        if (tv_playorpause.getText().toString().trim().equals("播放")) {
            pause();
        }
        //设置contentView
        View contentView = LayoutInflater.from(CourseDetailsActivity.this).inflate(R.layout.course_popwindowlayout, null);
        mPopWindow = new PopupWindow(contentView,
                WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);

        //倒计时
        downtime = (TextView) contentView.findViewById(R.id.tv_photo3);
        tv_photo2 = (TextView) contentView.findViewById(R.id.tv_photo2);
        tv_photo4 = (TextView) contentView.findViewById(R.id.tv_photo4);
        tv_photo1 = (TextView) contentView.findViewById(R.id.tv_photo1);
        tv_photo = (TextView) contentView.findViewById(R.id.tv_photo);
        img_photo = (ImageView) contentView.findViewById(R.id.img_photo);
        TextPaint paint = downtime.getPaint();
        paint.setFakeBoldText(true);//字体加粗
        ImageView takepciture = (ImageView) contentView.findViewById(R.id.img_photo1);//点拍照
        LinearLayout le_takepicture = (LinearLayout) contentView.findViewById(R.id.le_takepicture);//跟布局
        takepciture.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mOffTime.cancel();
                timerTask.cancel();
                mPopWindow.dismiss();
                SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                        Context.MODE_PRIVATE);
                String photoUrl = sp.getString("photoUrl", "");
                int faceRecgMark = sp.getInt("faceRecgMark", 0);
                Bundle bundle = new Bundle();
                bundle.putInt("faceRecgMark", faceRecgMark);
                bundle.putString("photoUrl", photoUrl);
                startActivityForResult(TakefacePhotoActivity.class, bundle, 0);
            }
        });

//        mPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
//            @Override
//            public void onDismiss() {
//                // popupWindow隐藏时恢复屏幕正常透明度
//                setBackgroundAlpha(1.0f);
//
//        }
//        });
//        setBackgroundAlpha(0.35f);//设置屏幕透明度
//        mPopWindow.setBackgroundDrawable(new BitmapDrawable());
        mPopWindow.setFocusable(false);
        mPopWindow.setOutsideTouchable(false);
        mPopWindow.showAtLocation(le_takepicture, Gravity.CENTER, 0, 0);

        //////倒计时
        mOffTime = new Timer(true);
        TimerTask tt = new TimerTask() {
            int countTime = 15;

            public void run() {
                if (countTime > 0) {
                    countTime--;
                }
                Message msg = new Message();
                msg.what = countTime;
                mOffHandler.sendMessage(msg);

            }
        };
        mOffTime.schedule(tt, 1000, 1000);
    }


    @SuppressLint("HandlerLeak")
    private void initDialog2() {
        if (tv_playorpause.getText().toString().trim().equals("播放")) {
            pause();
        }
        //设置contentView
        View contentView = LayoutInflater.from(CourseDetailsActivity.this).inflate(R.layout.test_popwindowlayout, null);
        mPopWindow2 = new PopupWindow(contentView,
                WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);


        ImageView takepciture = (ImageView) contentView.findViewById(R.id.img_photo1);//点拍照
        LinearLayout le_takepicture = (LinearLayout) contentView.findViewById(R.id.le_takepicture1);//跟布局
        takepciture.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                mPopWindow2.dismiss();
                SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                        Context.MODE_PRIVATE);
                String photoUrl = sp.getString("photoUrl", "");
                int faceRecgMark = sp.getInt("faceRecgMark", 0);
                Bundle bundle = new Bundle();
                bundle.putInt("faceRecgMark", faceRecgMark);
                bundle.putString("photoUrl", photoUrl);
                startActivityForResult(TakefacePhotoActivity.class, bundle, 0);
            }
        });

//        mPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
//            @Override
//            public void onDismiss() {
//                // popupWindow隐藏时恢复屏幕正常透明度
//                setBackgroundAlpha(1.0f);
//            }
//        });
//        setBackgroundAlpha(0.35f);//设置屏幕透明度
//        mPopWindow.setBackgroundDrawable(new BitmapDrawable());
        mPopWindow2.setFocusable(false);
        mPopWindow2.setOutsideTouchable(false);
        mPopWindow2.showAtLocation(le_takepicture, Gravity.CENTER, 0, 0);

    }

    @SuppressLint("HandlerLeak")
    private void initDialog3() {
        if (tv_playorpause.getText().toString().trim().equals("播放")) {
            pause();
        }
        //设置contentView
        View contentView = LayoutInflater.from(CourseDetailsActivity.this).inflate(R.layout.course_popwindowlayout, null);
        mPopWindow = new PopupWindow(contentView,
                WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);

        //倒计时
        downtime = (TextView) contentView.findViewById(R.id.tv_photo3);
        tv_photo2 = (TextView) contentView.findViewById(R.id.tv_photo2);
        tv_photo4 = (TextView) contentView.findViewById(R.id.tv_photo4);
        tv_photo1 = (TextView) contentView.findViewById(R.id.tv_photo1);
        tv_photo = (TextView) contentView.findViewById(R.id.tv_photo);
        img_photo = (ImageView) contentView.findViewById(R.id.img_photo);
        TextPaint paint = downtime.getPaint();
        paint.setFakeBoldText(true);//字体加粗
        ImageView takepciture = (ImageView) contentView.findViewById(R.id.img_photo1);//点拍照
        LinearLayout le_takepicture = (LinearLayout) contentView.findViewById(R.id.le_takepicture);//跟布局
        takepciture.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mOffTime.cancel();
                timerTask.cancel();
                mPopWindow.dismiss();
                SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                        Context.MODE_PRIVATE);
                String photoUrl = sp.getString("photoUrl", "");
                int faceRecgMark = sp.getInt("faceRecgMark", 0);
                Bundle bundle = new Bundle();
                bundle.putInt("faceRecgMark", faceRecgMark);
                bundle.putString("photoUrl", photoUrl);
                startActivityForResult(TakefacePhotoActivity.class, bundle, 2);
            }
        });

//        mPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
//            @Override
//            public void onDismiss() {
//                // popupWindow隐藏时恢复屏幕正常透明度
//                setBackgroundAlpha(1.0f);
//
//        }
//        });
//        setBackgroundAlpha(0.35f);//设置屏幕透明度
//        mPopWindow.setBackgroundDrawable(new BitmapDrawable());
        mPopWindow.setFocusable(false);
        mPopWindow.setOutsideTouchable(false);
        mPopWindow.showAtLocation(le_takepicture, Gravity.CENTER, 0, 0);

        //////倒计时
        mOffTime = new Timer(true);
        TimerTask tt = new TimerTask() {
            int countTime = 15;

            public void run() {
                if (countTime > 0) {
                    countTime--;
                }
                Message msg = new Message();
                msg.what = countTime;
                mOffHandler.sendMessage(msg);

            }
        };
        mOffTime.schedule(tt, 1000, 1000);
    }

    //拍照第二张
//    @SuppressLint("HandlerLeak")
//    private void initDialog3() {
//        if(tv_playorpause.getText().toString().trim().equals("播放"))
//        {
//            pause();
//        }
//        //设置contentView
//        View contentView = LayoutInflater.from(CourseDetailsActivity.this).inflate(R.layout.test_popwindowlayout, null);
//        mPopWindow2 = new PopupWindow(contentView,
//                WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);
//
//
//        ImageView takepciture = (ImageView)contentView.findViewById(R.id.img_photo1);//点拍照
//        LinearLayout le_takepicture = (LinearLayout)contentView.findViewById(R.id.le_takepicture1);//跟布局
//        takepciture.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//
//                mPopWindow2.dismiss();
//                SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
//                        Context.MODE_PRIVATE);
//                int faceRecgMark = sp.getInt("faceRecgMark", 0);
//                String photoUrl = sp.getString("photoUrl", "");
//                Bundle bundle = new Bundle();
//                bundle.putInt("faceRecgMark", faceRecgMark);
//                bundle.putString("photoUrl",photoUrl);
//                startActivityForResult(TakefacePhotoActivity.class,bundle, 2);
//            }
//        });
//        mPopWindow2.setFocusable(false);
//        mPopWindow2.setOutsideTouchable(false);
//        mPopWindow2.showAtLocation(le_takepicture, Gravity.CENTER, 0, 0);
//
//    }
    @SuppressLint("HandlerLeak")
    private void initDialog4() {
        if (tv_playorpause.getText().toString().trim().equals("播放")) {
            pause();
        }
        //设置contentView
        View contentView = LayoutInflater.from(CourseDetailsActivity.this).inflate(R.layout.course_popwindowlayout, null);
        mPopWindow = new PopupWindow(contentView,
                WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);

        //倒计时
        downtime = (TextView) contentView.findViewById(R.id.tv_photo3);
        tv_photo2 = (TextView) contentView.findViewById(R.id.tv_photo2);
        tv_photo4 = (TextView) contentView.findViewById(R.id.tv_photo4);
        tv_photo1 = (TextView) contentView.findViewById(R.id.tv_photo1);
        tv_photo = (TextView) contentView.findViewById(R.id.tv_photo);
        img_photo = (ImageView) contentView.findViewById(R.id.img_photo);
        TextPaint paint = downtime.getPaint();
        paint.setFakeBoldText(true);//字体加粗
        ImageView takepciture = (ImageView) contentView.findViewById(R.id.img_photo1);//点拍照
        LinearLayout le_takepicture = (LinearLayout) contentView.findViewById(R.id.le_takepicture);//跟布局
        takepciture.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mOffTime.cancel();
                timerTask.cancel();
                mPopWindow.dismiss();
                SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                        Context.MODE_PRIVATE);
                String photoUrl = sp.getString("photoUrl", "");
                int faceRecgMark = sp.getInt("faceRecgMark", 0);
                Bundle bundle = new Bundle();
                bundle.putInt("faceRecgMark", faceRecgMark);
                bundle.putString("photoUrl", photoUrl);
                startActivityForResult(TakefacePhotoActivity.class, bundle, 3);
            }
        });

//        mPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
//            @Override
//            public void onDismiss() {
//                // popupWindow隐藏时恢复屏幕正常透明度
//                setBackgroundAlpha(1.0f);
//
//        }
//        });
//        setBackgroundAlpha(0.35f);//设置屏幕透明度
//        mPopWindow.setBackgroundDrawable(new BitmapDrawable());
        mPopWindow.setFocusable(false);
        mPopWindow.setOutsideTouchable(false);
        mPopWindow.showAtLocation(le_takepicture, Gravity.CENTER, 0, 0);

        //////倒计时
        mOffTime = new Timer(true);
        TimerTask tt = new TimerTask() {
            int countTime = 15;

            public void run() {
                if (countTime > 0) {
                    countTime--;
                }
                Message msg = new Message();
                msg.what = countTime;
                mOffHandler.sendMessage(msg);

            }
        };
        mOffTime.schedule(tt, 1000, 1000);
    }

    //拍照第三张
//    @SuppressLint("HandlerLeak")
//    private void initDialog4() {
//        if(tv_playorpause.getText().toString().trim().equals("播放"))
//        {
//            pause();
//        }
//        //设置contentView
//        View contentView = LayoutInflater.from(CourseDetailsActivity.this).inflate(R.layout.test_popwindowlayout, null);
//        mPopWindow2 = new PopupWindow(contentView,
//                WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);
//
//
//        ImageView takepciture = (ImageView)contentView.findViewById(R.id.img_photo1);//点拍照
//        LinearLayout le_takepicture = (LinearLayout)contentView.findViewById(R.id.le_takepicture1);//跟布局
//        takepciture.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//
//                mPopWindow2.dismiss();
//                SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
//                        Context.MODE_PRIVATE);
//                int faceRecgMark = sp.getInt("faceRecgMark", 0);
//                String photoUrl = sp.getString("photoUrl", "");
//                Bundle bundle = new Bundle();
//                bundle.putInt("faceRecgMark", faceRecgMark);
//                bundle.putString("photoUrl",photoUrl);
//                startActivityForResult(TakefacePhotoActivity.class,bundle, 3);
//            }
//        });
//        mPopWindow2.setFocusable(false);
//        mPopWindow2.setOutsideTouchable(false);
//        mPopWindow2.showAtLocation(le_takepicture, Gravity.CENTER, 0, 0);
//
//    }
    @SuppressLint("HandlerLeak")
    private void initDialog5() {
        if (tv_playorpause.getText().toString().trim().equals("播放")) {
            pause();
        }
        //设置contentView
        View contentView = LayoutInflater.from(CourseDetailsActivity.this).inflate(R.layout.course_popwindowlayout, null);
        mPopWindow = new PopupWindow(contentView,
                WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);

        //倒计时
        downtime = (TextView) contentView.findViewById(R.id.tv_photo3);
        tv_photo2 = (TextView) contentView.findViewById(R.id.tv_photo2);
        tv_photo4 = (TextView) contentView.findViewById(R.id.tv_photo4);
        tv_photo1 = (TextView) contentView.findViewById(R.id.tv_photo1);
        tv_photo = (TextView) contentView.findViewById(R.id.tv_photo);
        img_photo = (ImageView) contentView.findViewById(R.id.img_photo);
        TextPaint paint = downtime.getPaint();
        paint.setFakeBoldText(true);//字体加粗
        ImageView takepciture = (ImageView) contentView.findViewById(R.id.img_photo1);//点拍照
        LinearLayout le_takepicture = (LinearLayout) contentView.findViewById(R.id.le_takepicture);//跟布局
        takepciture.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mOffTime.cancel();
                timerTask.cancel();
                mPopWindow.dismiss();
                SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                        Context.MODE_PRIVATE);
                String photoUrl = sp.getString("photoUrl", "");
                int faceRecgMark = sp.getInt("faceRecgMark", 0);
                Bundle bundle = new Bundle();
                bundle.putInt("faceRecgMark", faceRecgMark);
                bundle.putString("photoUrl", photoUrl);
                startActivityForResult(TakefacePhotoActivity.class, bundle, 4);
            }
        });

//        mPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
//            @Override
//            public void onDismiss() {
//                // popupWindow隐藏时恢复屏幕正常透明度
//                setBackgroundAlpha(1.0f);
//
//        }
//        });
//        setBackgroundAlpha(0.35f);//设置屏幕透明度
//        mPopWindow.setBackgroundDrawable(new BitmapDrawable());
        mPopWindow.setFocusable(false);
        mPopWindow.setOutsideTouchable(false);
        mPopWindow.showAtLocation(le_takepicture, Gravity.CENTER, 0, 0);

        //////倒计时
        mOffTime = new Timer(true);
        TimerTask tt = new TimerTask() {
            int countTime = 15;

            public void run() {
                if (countTime > 0) {
                    countTime--;
                }
                Message msg = new Message();
                msg.what = countTime;
                mOffHandler.sendMessage(msg);

            }
        };
        mOffTime.schedule(tt, 1000, 1000);
    }

    //拍照第四张
//    @SuppressLint("HandlerLeak")
//    private void initDialog5() {
//        if(tv_playorpause.getText().toString().trim().equals("播放"))
//        {
//            pause();
//        }
//        //设置contentView
//        View contentView = LayoutInflater.from(CourseDetailsActivity.this).inflate(R.layout.test_popwindowlayout, null);
//        mPopWindow2 = new PopupWindow(contentView,
//                WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);
//
//
//        ImageView takepciture = (ImageView)contentView.findViewById(R.id.img_photo1);//点拍照
//        LinearLayout le_takepicture = (LinearLayout)contentView.findViewById(R.id.le_takepicture1);//跟布局
//        takepciture.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//
//                mPopWindow2.dismiss();
//                SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
//                        Context.MODE_PRIVATE);
//                int faceRecgMark = sp.getInt("faceRecgMark", 0);
//                String photoUrl = sp.getString("photoUrl", "");
//                Bundle bundle = new Bundle();
//                bundle.putInt("faceRecgMark", faceRecgMark);
//                bundle.putString("photoUrl",photoUrl);
//                startActivityForResult(TakefacePhotoActivity.class,bundle, 4);
//            }
//        });
//        mPopWindow2.setFocusable(false);
//        mPopWindow2.setOutsideTouchable(false);
//        mPopWindow2.showAtLocation(le_takepicture, Gravity.CENTER, 0, 0);
//
//    }
    @SuppressLint("HandlerLeak")
    private void initDialog6() {
        if (tv_playorpause.getText().toString().trim().equals("播放")) {
            pause();
        }
        //设置contentView
        View contentView = LayoutInflater.from(CourseDetailsActivity.this).inflate(R.layout.course_popwindowlayout, null);
        mPopWindow = new PopupWindow(contentView,
                WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);

        //倒计时
        downtime = (TextView) contentView.findViewById(R.id.tv_photo3);
        tv_photo2 = (TextView) contentView.findViewById(R.id.tv_photo2);
        tv_photo4 = (TextView) contentView.findViewById(R.id.tv_photo4);
        tv_photo1 = (TextView) contentView.findViewById(R.id.tv_photo1);
        tv_photo = (TextView) contentView.findViewById(R.id.tv_photo);
        img_photo = (ImageView) contentView.findViewById(R.id.img_photo);
        TextPaint paint = downtime.getPaint();
        paint.setFakeBoldText(true);//字体加粗
        ImageView takepciture = (ImageView) contentView.findViewById(R.id.img_photo1);//点拍照
        LinearLayout le_takepicture = (LinearLayout) contentView.findViewById(R.id.le_takepicture);//跟布局
        takepciture.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mOffTime.cancel();
                timerTask.cancel();
                mPopWindow.dismiss();
                SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                        Context.MODE_PRIVATE);
                String photoUrl = sp.getString("photoUrl", "");
                int faceRecgMark = sp.getInt("faceRecgMark", 0);
                Bundle bundle = new Bundle();
                bundle.putInt("faceRecgMark", faceRecgMark);
                bundle.putString("photoUrl", photoUrl);
                startActivityForResult(TakefacePhotoActivity.class, bundle, 5);
            }
        });

//        mPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
//            @Override
//            public void onDismiss() {
//                // popupWindow隐藏时恢复屏幕正常透明度
//                setBackgroundAlpha(1.0f);
//
//        }
//        });
//        setBackgroundAlpha(0.35f);//设置屏幕透明度
//        mPopWindow.setBackgroundDrawable(new BitmapDrawable());
        mPopWindow.setFocusable(false);
        mPopWindow.setOutsideTouchable(false);
        mPopWindow.showAtLocation(le_takepicture, Gravity.CENTER, 0, 0);

        //////倒计时
        mOffTime = new Timer(true);
        TimerTask tt = new TimerTask() {
            int countTime = 15;

            public void run() {
                if (countTime > 0) {
                    countTime--;
                }
                Message msg = new Message();
                msg.what = countTime;
                mOffHandler.sendMessage(msg);

            }
        };
        mOffTime.schedule(tt, 1000, 1000);
    }
    //拍照第五张
    //   @SuppressLint("HandlerLeak")
//    private void initDialog6() {
//        if(tv_playorpause.getText().toString().trim().equals("播放"))
//        {
//            pause();
//        }
//        //设置contentView
//        View contentView = LayoutInflater.from(CourseDetailsActivity.this).inflate(R.layout.test_popwindowlayout, null);
//        mPopWindow2 = new PopupWindow(contentView,
//                WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);
//
//
//        ImageView takepciture = (ImageView)contentView.findViewById(R.id.img_photo1);//点拍照
//        LinearLayout le_takepicture = (LinearLayout)contentView.findViewById(R.id.le_takepicture1);//跟布局
//        takepciture.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//
//                mPopWindow2.dismiss();
//                SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
//                        Context.MODE_PRIVATE);
//                int faceRecgMark = sp.getInt("faceRecgMark", 0);
//                String photoUrl = sp.getString("photoUrl", "");
//                Bundle bundle = new Bundle();
//                bundle.putInt("faceRecgMark", faceRecgMark);
//                bundle.putString("photoUrl",photoUrl);
//                startActivityForResult(TakefacePhotoActivity.class,bundle, 5);
//            }
//        });
//        mPopWindow2.setFocusable(false);
//        mPopWindow2.setOutsideTouchable(false);
//        mPopWindow2.showAtLocation(le_takepicture, Gravity.CENTER, 0, 0);
//
//    }


    @SuppressLint("HandlerLeak")
//    private void initStopDialog() {
//        //设置contentView
//        View contentView = LayoutInflater.from(CourseDetailsActivity.this).inflate(R.layout.stop_popwindowlayout, null);
//        mStopPopWindow = new PopupWindow(contentView,
//                WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);
//        ImageView takepciture1 = (ImageView) contentView.findViewById(R.id.img_photo1);//点拍照
//        //    LinearLayout le_takepicture = (LinearLayout)contentView.findViewById(R.id.le_takepicture);//跟布局
//        takepciture1.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                ishave =false;
//                mStopPopWindow.dismiss();
//                if (photoMark == 1) {
//                    Thread thread = new Thread(new Runnable() {
//                        @Override
//                        public void run() {
//                            //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
//                            mHandler.sendEmptyMessage(0);
//                        }
//                    });
//                    thread.start();
//                } else if (photoMark == 0) {
//                    Thread thread = new Thread(new Runnable() {
//                        @Override
//                        public void run() {
//                            //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
//                            mHandler.sendEmptyMessage(2);
//                        }
//                    });
//                    thread.start();
//                }else if(photoMark == 2)
//                {
//                    Thread thread = new Thread(new Runnable() {
//                        @Override
//                        public void run() {
//                            //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
//                            mHandler.sendEmptyMessage(3);
//                        }
//                    });
//                    thread.start();
//
//                }else if(photoMark == 3)
//                {
//                    Thread thread = new Thread(new Runnable() {
//                        @Override
//                        public void run() {
//                            //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
//                            mHandler.sendEmptyMessage(4);
//                        }
//                    });
//                    thread.start();
//
//                }else if(photoMark == 4)
//                {
//                    Thread thread = new Thread(new Runnable() {
//                        @Override
//                        public void run() {
//                            //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
//                            mHandler.sendEmptyMessage(5);
//                        }
//                    });
//                    thread.start();
//
//                }else if(photoMark == 5)
//                {
//                    Thread thread = new Thread(new Runnable() {
//                        @Override
//                        public void run() {
//                            //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
//                            mHandler.sendEmptyMessage(6);
//                        }
//                    });
//                    thread.start();
//
//                }
//
//            }
//        });
//
////        mPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
////            @Override
////            public void onDismiss() {
////                // popupWindow隐藏时恢复屏幕正常透明度
////                setBackgroundAlpha(1.0f);
////            }
////        });
////        setBackgroundAlpha(0.35f);//设置屏幕透明度
////        mPopWindow.setBackgroundDrawable(new BitmapDrawable());
//        mStopPopWindow.setFocusable(false);
//        mStopPopWindow.setOutsideTouchable(false);
//        mStopPopWindow.showAtLocation(le_parement, Gravity.CENTER, 0, 0);
//
//    }
    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {
        if (mPopWindow != null && mPopWindow.isShowing()) {
            return false;
        }
        if (mSorryPopWindow != null && mSorryPopWindow.isShowing()) {
            return false;
        }
        if (mStopPopWindow != null && mStopPopWindow.isShowing()) {
            return false;
        }
        if (mPopWindow2 != null && mPopWindow2.isShowing()) {
            return false;
        }
        return super.dispatchTouchEvent(event);
    }

    private void ShowSorryPopwindow() {

        View contentView = LayoutInflater.from(CourseDetailsActivity.this).inflate(R.layout.sorry_popwindowlayout, null);
        mSorryPopWindow = new PopupWindow(contentView,
                WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);
        LinearLayout le_sorry = (LinearLayout) contentView.findViewById(R.id.le_sorry);//跟布局
        ImageView sorry_exit = (ImageView) contentView.findViewById(R.id.sorry_img_photo1);//退出
        sorry_exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                tv_pause.setVisibility(View.VISIBLE);
//                tv_pause.setText("暂停学习");
                mSorryPopWindow.dismiss();
                SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                        Context.MODE_PRIVATE);
                SharedPreferences.Editor edit = sp.edit();
                edit.remove("format");
                edit.commit();
                if (photoMark == 1) {
                    Thread thread = new Thread(new Runnable() {
                        @Override
                        public void run() {
                            //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
                            mHandler.sendEmptyMessage(0);
                        }
                    });
                    thread.start();
                } else if (photoMark == 2) {
                    Thread thread = new Thread(new Runnable() {
                        @Override
                        public void run() {
                            //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
                            mHandler.sendEmptyMessage(3);
                        }
                    });
                    thread.start();
                } else if (photoMark == 3) {
                    Thread thread = new Thread(new Runnable() {
                        @Override
                        public void run() {
                            //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
                            mHandler.sendEmptyMessage(4);
                        }
                    });
                    thread.start();
                } else if (photoMark == 4) {
                    Thread thread = new Thread(new Runnable() {
                        @Override
                        public void run() {
                            //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
                            mHandler.sendEmptyMessage(5);
                        }
                    });
                    thread.start();

                } else if (photoMark == 5) {
                    Thread thread = new Thread(new Runnable() {
                        @Override
                        public void run() {
                            //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
                            mHandler.sendEmptyMessage(6);
                        }
                    });
                    thread.start();

                }


            }
        });
//        mSorryPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
//            @Override
//            public void onDismiss() {
//                // popupWindow隐藏时恢复屏幕正常透明度
//                setBackgroundAlpha(1.0f);
//            }
//        });
//        setBackgroundAlpha(0.35f);//设置屏幕透明度
//        mSorryPopWindow.setBackgroundDrawable(new BitmapDrawable());
        mSorryPopWindow.setFocusable(false);
        mSorryPopWindow.setOutsideTouchable(false);
        mSorryPopWindow.showAtLocation(le_sorry, Gravity.CENTER, 0, 0);

    }
//    private Camera.Size getOptimalPreviewSize(List<Camera.Size> sizes, int w, int h) {
//        final double ASPECT_TOLERANCE = 0.1;
//        double targetRatio = (double) w / h;
//        if (sizes == null) return null;
//
//        Camera.Size optimalSize = null;
//        double minDiff = Double.MAX_VALUE;
//
//        int targetHeight = h;
//
//        // Try to find an size match aspect ratio and size
//        for (Camera.Size size : sizes) {
//            double ratio = (double) size.width / size.height;
//            if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue;
//            if (Math.abs(size.height - targetHeight) < minDiff) {
//                optimalSize = size;
//                minDiff = Math.abs(size.height - targetHeight);
//            }
//        }
//
//        // Cannot find the one match the aspect ratio, ignore the requirement
//        if (optimalSize == null) {
//            minDiff = Double.MAX_VALUE;
//            for (Camera.Size size : sizes) {
//                if (Math.abs(size.height - targetHeight) < minDiff) {
//                    optimalSize = size;
//                    minDiff = Math.abs(size.height - targetHeight);
//                }
//            }
//        }
//        return optimalSize;
//    }

    /**
     * 设置添加屏幕的背景透明度
     *
     * @param bgAlpha 屏幕透明度0.0-1.0 1表示完全不透明
     */
    public void setBackgroundAlpha(float bgAlpha) {
        WindowManager.LayoutParams lp = (CourseDetailsActivity.this).getWindow()
                .getAttributes();
        lp.alpha = bgAlpha;
        (CourseDetailsActivity.this).getWindow().setAttributes(lp);
    }

    @Override
    public void onBackPressed() {
        if (Jzvd.backPress()) {
            return;
        }

        if (setYm.equals("")) {

            TiShiDialog.Builder builder1 = new TiShiDialog.Builder(CourseDetailsActivity.this);
            builder1.setMessage("仅查看,不能保存记录");
            builder1.setTitle("提示:");
            builder1.setPositiveButton("确定退出", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                            Context.MODE_PRIVATE);
                    SharedPreferences.Editor edit = sp.edit();
                    edit.clear();
                    edit.commit();
//                        LoginUserBean userInfo = UserManger.getUserInfo();
//                        String userId = userInfo.getData().getUserId();
//                        SharedPreferences sp = getSharedPreferences("durationandformat1" + userId,
//                                Context.MODE_PRIVATE);
//                        int otcSn = sp.getInt("otcSn", 0);
//                        int learnsn = sp.getInt("learnsn", 0);
//                        String format = sp.getString("format"+ otcSn+learnsn, "");
//                        String imgurl = sp.getString("imgurl"+ otcSn+learnsn, "");
//                        int tcsn = sp.getInt("tcsn", 0);
//                        int sn = sp.getInt("sn", 0);
//                        String statYm = sp.getString("statYm", "");
//                        String orgId = sp.getString("orgId", "");
//                        String[] splitformat = format.split(":");
//                        String format1 = splitformat[0];
//                        String format2 = splitformat[1];
//                        String format3 = splitformat[2];
//                        int iformat1 = Integer.valueOf(format1);//转int
//                        int iformat2 = Integer.valueOf(format2);//转int
//                        int iformat3 = Integer.valueOf(format3);//转int
//                        int formattime = iformat1 * 3600 + iformat2 * 60 + iformat3 * 1;
//                        int photoMark = sp.getInt("photoMark", 0);
//                        if(photoMark==1)
//                        {
//                            int readLength = (formattime%60==0)?formattime/60:(formattime/60+1);//累计学习时间
//                            LogUtils.e("readLength",readLength+"");
//                            String firsttime = sp.getString("firsttime"+ otcSn, "");//第一次抓拍时间
//                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
//                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
//                            //                     String durationsub = duration.substring(3, 8);//截取字符串00:00:00变成00:00
//                            UserTcPhoto userTcPhoto = new UserTcPhoto();
//                            userTcPhoto.setSnapTime(firsttimesub);
//                            userTcPhoto.setUrl(imgurl);
//                            photoList.add(userTcPhoto);
//                            Gson gson = new Gson();
//                            String strphotoList = gson.toJson(photoList);
//                            LogUtils.e("strphotoList",strphotoList);
//                            initsavedata(sn,userId,orgId,tcsn,otcSn,learnsn,readLength,photoList);
//                        }else if(photoMark==0){
//                            int readLength = (formattime%60==0)?formattime/60:(formattime/60+1);//累计学习时间
//                            LogUtils.e("readLength",readLength+"");
//                            String firsttime = sp.getString("firsttime"+ otcSn, "");//第一次抓拍时间
//                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
//                            //      String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
//                            //                     String durationsub = duration.substring(3, 8);//截取字符串00:00:00变成00:00
//                            UserTcPhoto userTcPhoto = new UserTcPhoto();
//                            userTcPhoto.setSnapTime(firsttime);
//                            userTcPhoto.setUrl(imgurl);
//                            photoList.add(userTcPhoto);
//                            Gson gson = new Gson();
//                            String strphotoList = gson.toJson(photoList);
//                            LogUtils.e("strphotoList",strphotoList);
//                            initsavedata(sn,userId,orgId,tcsn,otcSn,learnsn,readLength,photoList);
//                        }
                    timerTask.cancel();
                    timer1.cancel();
                    timerTask = null;
                    timer1 = null;
                    finish();

                }
            });
            builder1.setNegativeButton("继续学习",
                    new android.content.DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            //     initStopDialog();
                            dialog.dismiss();
                        }
                    });
            builder1.create().show();
            return;
        }

//        SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
//                Context.MODE_PRIVATE);
//
//        String formatime = sp.getString("format", "");
//        String firsttime = sp.getString("firsttime", "");
//        if (formatime.equals(firsttime)) {
//            Toast.makeText(CourseDetailsActivity.this, "拍照期间暂时不能退出当前界面", Toast.LENGTH_LONG).show();
//        } else {
        SharedPreferences sp1 = getSharedPreferences("CourseDetailsActivity",
                Context.MODE_PRIVATE);
        String formats2 = sp1.getString("format", "");
        int courseLength2 = sp1.getInt("courseLength", 0);
        String[] splitformat2 = formats2.split(":");
        String formatstr7 = splitformat2[0];
        String formatstr8 = splitformat2[1];
        String formatstr9 = splitformat2[2];
        int iformat7 = Integer.valueOf(formatstr7);//转int
        int iformat8 = Integer.valueOf(formatstr8);//转int
        int iformat9 = Integer.valueOf(formatstr9);//转int
        int formattime2 = iformat7 * 3600 + iformat8 * 60 + iformat9 * 1;
        if (formattime2 < 60) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            View view1 = View.inflate(CourseDetailsActivity.this, R.layout.diolog_learn_layout, null);
            TextView tv_message = (TextView) view1.findViewById(R.id.message);//输入内容
            tv_message.setText("您本次学习未满一分钟，无法保存学习进度，退出后将重新学习本课程。");
            TextView btn_sure = (TextView) view1.findViewById(R.id.positiveButton);
            TextView btn_cancel = (TextView) view1.findViewById(R.id.negativeButton);
            btn_sure.setText("确认退出");
            btn_cancel.setText("继续学习");
            final AlertDialog dialog = builder.create();
            dialog.show();
            dialog.getWindow().setContentView(view1);
            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            dialog.setCancelable(false);
            btn_sure.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    dialog.dismiss();
                    SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                            Context.MODE_PRIVATE);
                    SharedPreferences.Editor edit = sp.edit();
                    edit.clear();
                    edit.commit();
                    timerTask.cancel();
                    timer1.cancel();
                    timerTask = null;
                    timer1 = null;
                    finish();
                    //设置你的操作事项
                }
            });

            btn_cancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    dialog.dismiss();
                }
            });


        } else {
            if (formattime2 == courseLength2 * 60)//课程达到课程时长点保存相当于提交
            {
                if (rowsList.size() != 0) {
                    for (int i = 0; i < rowsList.size(); i++) {
                        if (rowsList.get(i).isSelect() == false) {
                            TiShiDialog.Builder builder1 = new TiShiDialog.Builder(this);
                            builder1.setMessage("第" + (i + 1) + "测验题未答，请答题");
                            builder1.setTitle("提示:");
                            builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    ;
                                    //设置你的操作事项
                                }
                            });
                            builder1.create().show();

                            return;
                        } else {
                            if (rowsList.get(i).isLOOP() == false) {
                                TiShiDialog.Builder builder1 = new TiShiDialog.Builder(this);
                                builder1.setMessage("第" + (i + 1) + "测验题回答错误，请重新答题");
                                builder1.setTitle("提示:");
                                builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.dismiss();
                                        ;
                                        //设置你的操作事项
                                    }
                                });
                                builder1.create().show();


                                return;
                            }
                        }
                    }
                    //有题目接口
                    int tcsn = sp1.getInt("tcsn", 0);
                    int learnsn = sp1.getInt("learnsn", 0);
                    String orgId = sp1.getString("orgId", "");
                    if (photoMark == 1) {
                        LoginUserBean userInfo = UserManger.getUserInfo();
                        String userId = userInfo.getData().getUserId();//useid
                        String firsttimestr = sp1.getString("firsttime", "");//第一次抓拍时间
                        String imgurl = sp1.getString("imgurl", "");//第一次拍照图片地址获取
                        String firsttimesub = firsttimestr.substring(3, 8);//截取字符串00:00:00变成00:00
                        List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                        UserTcPhoto userTcPhoto = new UserTcPhoto();
                        userTcPhoto.setUrl(imgurl);
                        userTcPhoto.setSnapTime(firsttimesub);
                        photoList.add(userTcPhoto);
                        Gson gson = new Gson();
                        String strphotoList = gson.toJson(photoList);
                        LogUtils.e("strphotoList", strphotoList);
                        mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                        mProgressDialog.setMessage("提交中...");
                        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        mProgressDialog.setCancelable(false);
                        mProgressDialog.show();
                        new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength2, 1, photoList, this, 3);
                    } else if (photoMark == 0) {
                        LoginUserBean userInfo = UserManger.getUserInfo();
                        String userId = userInfo.getData().getUserId();//useid
                        String firsttimestr = sp1.getString("firsttime", "");//第一次抓拍时间
                        String imgurl = sp1.getString("imgurl", "");//第一次拍照图片地址获取
                        List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                        UserTcPhoto userTcPhoto = new UserTcPhoto();
                        userTcPhoto.setUrl(imgurl);
                        userTcPhoto.setSnapTime(firsttimestr);
                        photoList.add(userTcPhoto);
                        Gson gson = new Gson();
                        String strphotoList = gson.toJson(photoList);
                        LogUtils.e("strphotoList", strphotoList);
                        mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                        mProgressDialog.setMessage("提交中...");
                        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        mProgressDialog.setCancelable(false);
                        mProgressDialog.show();
                        new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength2, 1, photoList, this, 3);
                    } else if (photoMark == 2) {
                        LoginUserBean userInfo = UserManger.getUserInfo();
                        String userId = userInfo.getData().getUserId();//useid
                        String imgurl = sp1.getString("imgurl", "");
                        String imgurl1 = sp1.getString("imgurl1", "");
                        String firsttimestr = sp1.getString("firsttime", "");//第一次抓拍时间
                        String numFifthpartstr = sp1.getString("numFifthpartstr", "");//第二次抓拍时间
                        String firsttimesub = firsttimestr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                        UserTcPhoto userTcPhoto = new UserTcPhoto();
                        userTcPhoto.setUrl(imgurl);
                        userTcPhoto.setSnapTime(firsttimesub);
                        UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                        userTcPhoto1.setUrl(imgurl1);
                        userTcPhoto1.setSnapTime(numFifthpartstr1);
                        photoList.add(userTcPhoto);
                        photoList.add(userTcPhoto1);
                        Gson gson = new Gson();
                        String strphotoList = gson.toJson(photoList);
                        LogUtils.e("strphotoList", strphotoList);
                        mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                        mProgressDialog.setMessage("提交中...");
                        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        mProgressDialog.setCancelable(false);
                        mProgressDialog.show();
                        new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength2, 1, photoList, this, 3);
                    } else if (photoMark == 3) {
                        LoginUserBean userInfo = UserManger.getUserInfo();
                        String userId = userInfo.getData().getUserId();//useid
                        String imgurl1 = sp1.getString("imgurl", "");
                        String firsttimestr = sp1.getString("firsttime", "");//第一次抓拍时间
                        String imgurl2 = sp1.getString("imgurl1", "");
                        String numsecondpartstr = sp1.getString("numsecondpartstr", "");//第二次抓拍时间
                        String imgurl3 = sp1.getString("imgurl2", "");
                        String numFifthpartstr = sp1.getString("numFifthpartstr", "");//第三次抓拍时间
                        String firsttimesub = firsttimestr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                        UserTcPhoto userTcPhoto = new UserTcPhoto();
                        userTcPhoto.setUrl(imgurl1);
                        userTcPhoto.setSnapTime(firsttimesub);
                        UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                        userTcPhoto1.setUrl(imgurl2);
                        userTcPhoto1.setSnapTime(numsecondpartstr1);
                        UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                        userTcPhoto2.setUrl(imgurl3);
                        userTcPhoto2.setSnapTime(numFifthpartstr1);
                        photoList.add(userTcPhoto);
                        photoList.add(userTcPhoto1);
                        photoList.add(userTcPhoto2);
                        Gson gson = new Gson();
                        String strphotoList = gson.toJson(photoList);
                        LogUtils.e("strphotoList", strphotoList);
                        mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                        mProgressDialog.setMessage("提交中...");
                        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        mProgressDialog.setCancelable(false);
                        mProgressDialog.show();
                        new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength2, 1, photoList, this, 3);
                    } else if (photoMark == 4) {
                        LoginUserBean userInfo = UserManger.getUserInfo();
                        String userId = userInfo.getData().getUserId();//useid
                        String imgurl = sp1.getString("imgurl", "");
                        String imgurl1 = sp1.getString("imgurl1", "");
                        String imgurl2 = sp1.getString("imgurl2", "");
                        String imgurl3 = sp1.getString("imgurl3", "");
                        String firsttimestr = sp1.getString("firsttime", "");//第一次抓拍时间
                        String numsecondpartstr = sp1.getString("numsecondpartstr", "");//第二次抓拍时间
                        String numthirdpartstr = sp1.getString("numthirdpartstr", "");//第三次抓拍时间
                        String numFifthpartstr = sp1.getString("numFifthpartstr", "");//第四次抓拍时间
                        String firsttimesub = firsttimestr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numthirdpartstr1 = numthirdpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                        UserTcPhoto userTcPhoto = new UserTcPhoto();
                        userTcPhoto.setUrl(imgurl);
                        userTcPhoto.setSnapTime(firsttimesub);
                        UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                        userTcPhoto1.setUrl(imgurl1);
                        userTcPhoto1.setSnapTime(numsecondpartstr1);
                        UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                        userTcPhoto2.setUrl(imgurl2);
                        userTcPhoto2.setSnapTime(numthirdpartstr1);
                        UserTcPhoto userTcPhoto3 = new UserTcPhoto();
                        userTcPhoto3.setUrl(imgurl3);
                        userTcPhoto3.setSnapTime(numFifthpartstr1);
                        photoList.add(userTcPhoto);
                        photoList.add(userTcPhoto1);
                        photoList.add(userTcPhoto2);
                        photoList.add(userTcPhoto3);
                        Gson gson = new Gson();
                        String strphotoList = gson.toJson(photoList);
                        LogUtils.e("strphotoList", strphotoList);
                        mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                        mProgressDialog.setMessage("提交中...");
                        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        mProgressDialog.setCancelable(false);
                        mProgressDialog.show();
                        new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength2, 1, photoList, this, 3);
                    } else if (photoMark == 5) {
                        LoginUserBean userInfo = UserManger.getUserInfo();
                        String userId = userInfo.getData().getUserId();//useid
                        String imgurl = sp1.getString("imgurl", "");
                        String imgurl1 = sp1.getString("imgurl1", "");
                        String imgurl2 = sp1.getString("imgurl2", "");
                        String imgurl3 = sp1.getString("imgurl3", "");
                        String imgurl4 = sp1.getString("imgurl4", "");
                        String firsttimestr = sp1.getString("firsttime", "");//第一次抓拍时间
                        String numsecondpartstr = sp1.getString("numsecondpartstr", "");//第二次抓拍时间
                        String numthirdpartstr = sp1.getString("numthirdpartstr", "");//第三次抓拍时间
                        String numfourpartstr = sp1.getString("numfourpartstr", "");//第四次抓拍时间
                        String numFifthpartstr = sp1.getString("numFifthpartstr", "");//第五次抓拍时间
                        String firsttimesub = firsttimestr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numthirdpartstr1 = numthirdpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numfourpartstr1 = numfourpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                        UserTcPhoto userTcPhoto = new UserTcPhoto();
                        userTcPhoto.setUrl(imgurl);
                        userTcPhoto.setSnapTime(firsttimesub);
                        UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                        userTcPhoto1.setUrl(imgurl1);
                        userTcPhoto1.setSnapTime(numsecondpartstr1);
                        UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                        userTcPhoto2.setUrl(imgurl2);
                        userTcPhoto2.setSnapTime(numthirdpartstr1);
                        UserTcPhoto userTcPhoto3 = new UserTcPhoto();
                        userTcPhoto3.setUrl(imgurl3);
                        userTcPhoto3.setSnapTime(numfourpartstr1);
                        UserTcPhoto userTcPhoto4 = new UserTcPhoto();
                        userTcPhoto4.setUrl(imgurl4);
                        userTcPhoto4.setSnapTime(numFifthpartstr1);
                        photoList.add(userTcPhoto);
                        photoList.add(userTcPhoto1);
                        photoList.add(userTcPhoto2);
                        photoList.add(userTcPhoto3);
                        photoList.add(userTcPhoto4);
                        Gson gson = new Gson();
                        String strphotoList = gson.toJson(photoList);
                        LogUtils.e("strphotoList", strphotoList);
                        mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                        mProgressDialog.setMessage("提交中...");
                        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        mProgressDialog.setCancelable(false);
                        mProgressDialog.show();
                        new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength2, 1, photoList, this, 3);
                    }
                } else {//无题目接口
                    int tcsn = sp1.getInt("tcsn", 0);
                    int learnsn = sp1.getInt("learnsn", 0);
                    String orgId = sp1.getString("orgId", "");
                    if (photoMark == 1) {
                        LoginUserBean userInfo = UserManger.getUserInfo();
                        String userId = userInfo.getData().getUserId();//useid
                        String firsttimestr = sp1.getString("firsttime", "");//第一次抓拍时间
                        String imgurl = sp1.getString("imgurl", "");//第一次拍照图片地址获取
                        String firsttimesub = firsttimestr.substring(3, 8);//截取字符串00:00:00变成00:00
                        List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                        UserTcPhoto userTcPhoto = new UserTcPhoto();
                        userTcPhoto.setUrl(imgurl);
                        userTcPhoto.setSnapTime(firsttimesub);
                        photoList.add(userTcPhoto);
                        Gson gson = new Gson();
                        String strphotoList = gson.toJson(photoList);
                        LogUtils.e("strphotoList", strphotoList);
                        mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                        mProgressDialog.setMessage("提交中...");
                        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        mProgressDialog.setCancelable(false);
                        mProgressDialog.show();
                        new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength2, 1, photoList, this, 3);
                    } else if (photoMark == 0) {
                        LoginUserBean userInfo = UserManger.getUserInfo();
                        String userId = userInfo.getData().getUserId();//useid
                        String firsttimestr = sp1.getString("firsttime", "");//第一次抓拍时间
                        String imgurl = sp1.getString("imgurl", "");//第一次拍照图片地址获取
                        List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                        UserTcPhoto userTcPhoto = new UserTcPhoto();
                        userTcPhoto.setUrl(imgurl);
                        userTcPhoto.setSnapTime(firsttimestr);
                        photoList.add(userTcPhoto);
                        Gson gson = new Gson();
                        String strphotoList = gson.toJson(photoList);
                        LogUtils.e("strphotoList", strphotoList);
                        mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                        mProgressDialog.setMessage("提交中...");
                        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        mProgressDialog.setCancelable(false);
                        mProgressDialog.show();
                        new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength2, 1, photoList, this, 3);
                    } else if (photoMark == 2) {
                        LoginUserBean userInfo = UserManger.getUserInfo();
                        String userId = userInfo.getData().getUserId();//useid
                        String imgurl = sp1.getString("imgurl", "");
                        String imgurl1 = sp1.getString("imgurl1", "");
                        String firsttimestr = sp1.getString("firsttime", "");//第一次抓拍时间
                        String numFifthpartstr = sp1.getString("numFifthpartstr", "");//第二次抓拍时间
                        String firsttimesub = firsttimestr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                        UserTcPhoto userTcPhoto = new UserTcPhoto();
                        userTcPhoto.setUrl(imgurl);
                        userTcPhoto.setSnapTime(firsttimesub);
                        UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                        userTcPhoto1.setUrl(imgurl1);
                        userTcPhoto1.setSnapTime(numFifthpartstr1);
                        photoList.add(userTcPhoto);
                        photoList.add(userTcPhoto1);
                        Gson gson = new Gson();
                        String strphotoList = gson.toJson(photoList);
                        LogUtils.e("strphotoList", strphotoList);
                        mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                        mProgressDialog.setMessage("提交中...");
                        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        mProgressDialog.setCancelable(false);
                        mProgressDialog.show();
                        new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength2, 1, photoList, this, 3);
                    } else if (photoMark == 3) {
                        LoginUserBean userInfo = UserManger.getUserInfo();
                        String userId = userInfo.getData().getUserId();//useid
                        String imgurl1 = sp1.getString("imgurl", "");
                        String firsttimestr = sp1.getString("firsttime", "");//第一次抓拍时间
                        String imgurl2 = sp1.getString("imgurl1", "");
                        String numsecondpartstr = sp1.getString("numsecondpartstr", "");//第二次抓拍时间
                        String imgurl3 = sp1.getString("imgurl2", "");
                        String numFifthpartstr = sp1.getString("numFifthpartstr", "");//第三次抓拍时间
                        String firsttimesub = firsttimestr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                        UserTcPhoto userTcPhoto = new UserTcPhoto();
                        userTcPhoto.setUrl(imgurl1);
                        userTcPhoto.setSnapTime(firsttimesub);
                        UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                        userTcPhoto1.setUrl(imgurl2);
                        userTcPhoto1.setSnapTime(numsecondpartstr1);
                        UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                        userTcPhoto2.setUrl(imgurl3);
                        userTcPhoto2.setSnapTime(numFifthpartstr1);
                        photoList.add(userTcPhoto);
                        photoList.add(userTcPhoto1);
                        photoList.add(userTcPhoto2);
                        Gson gson = new Gson();
                        String strphotoList = gson.toJson(photoList);
                        LogUtils.e("strphotoList", strphotoList);
                        mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                        mProgressDialog.setMessage("提交中...");
                        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        mProgressDialog.setCancelable(false);
                        mProgressDialog.show();
                        new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength2, 1, photoList, this, 3);
                    } else if (photoMark == 4) {
                        LoginUserBean userInfo = UserManger.getUserInfo();
                        String userId = userInfo.getData().getUserId();//useid
                        String imgurl = sp1.getString("imgurl", "");
                        String imgurl1 = sp1.getString("imgurl1", "");
                        String imgurl2 = sp1.getString("imgurl2", "");
                        String imgurl3 = sp1.getString("imgurl3", "");
                        String firsttimestr = sp1.getString("firsttime", "");//第一次抓拍时间
                        String numsecondpartstr = sp1.getString("numsecondpartstr", "");//第二次抓拍时间
                        String numthirdpartstr = sp1.getString("numthirdpartstr", "");//第三次抓拍时间
                        String numFifthpartstr = sp1.getString("numFifthpartstr", "");//第四次抓拍时间
                        String firsttimesub = firsttimestr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numthirdpartstr1 = numthirdpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                        UserTcPhoto userTcPhoto = new UserTcPhoto();
                        userTcPhoto.setUrl(imgurl);
                        userTcPhoto.setSnapTime(firsttimesub);
                        UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                        userTcPhoto1.setUrl(imgurl1);
                        userTcPhoto1.setSnapTime(numsecondpartstr1);
                        UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                        userTcPhoto2.setUrl(imgurl2);
                        userTcPhoto2.setSnapTime(numthirdpartstr1);
                        UserTcPhoto userTcPhoto3 = new UserTcPhoto();
                        userTcPhoto3.setUrl(imgurl3);
                        userTcPhoto3.setSnapTime(numFifthpartstr1);
                        photoList.add(userTcPhoto);
                        photoList.add(userTcPhoto1);
                        photoList.add(userTcPhoto2);
                        photoList.add(userTcPhoto3);
                        Gson gson = new Gson();
                        String strphotoList = gson.toJson(photoList);
                        LogUtils.e("strphotoList", strphotoList);
                        mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                        mProgressDialog.setMessage("提交中...");
                        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        mProgressDialog.setCancelable(false);
                        mProgressDialog.show();
                        new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength2, 1, photoList, this, 3);
                    } else if (photoMark == 5) {
                        LoginUserBean userInfo = UserManger.getUserInfo();
                        String userId = userInfo.getData().getUserId();//useid
                        String imgurl = sp1.getString("imgurl", "");
                        String imgurl1 = sp1.getString("imgurl1", "");
                        String imgurl2 = sp1.getString("imgurl2", "");
                        String imgurl3 = sp1.getString("imgurl3", "");
                        String imgurl4 = sp1.getString("imgurl4", "");
                        String firsttimestr = sp1.getString("firsttime", "");//第一次抓拍时间
                        String numsecondpartstr = sp1.getString("numsecondpartstr", "");//第二次抓拍时间
                        String numthirdpartstr = sp1.getString("numthirdpartstr", "");//第三次抓拍时间
                        String numfourpartstr = sp1.getString("numfourpartstr", "");//第四次抓拍时间
                        String numFifthpartstr = sp1.getString("numFifthpartstr", "");//第五次抓拍时间
                        String firsttimesub = firsttimestr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numthirdpartstr1 = numthirdpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numfourpartstr1 = numfourpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                        UserTcPhoto userTcPhoto = new UserTcPhoto();
                        userTcPhoto.setUrl(imgurl);
                        userTcPhoto.setSnapTime(firsttimesub);
                        UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                        userTcPhoto1.setUrl(imgurl1);
                        userTcPhoto1.setSnapTime(numsecondpartstr1);
                        UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                        userTcPhoto2.setUrl(imgurl2);
                        userTcPhoto2.setSnapTime(numthirdpartstr1);
                        UserTcPhoto userTcPhoto3 = new UserTcPhoto();
                        userTcPhoto3.setUrl(imgurl3);
                        userTcPhoto3.setSnapTime(numfourpartstr1);
                        UserTcPhoto userTcPhoto4 = new UserTcPhoto();
                        userTcPhoto4.setUrl(imgurl4);
                        userTcPhoto4.setSnapTime(numFifthpartstr1);
                        photoList.add(userTcPhoto);
                        photoList.add(userTcPhoto1);
                        photoList.add(userTcPhoto2);
                        photoList.add(userTcPhoto3);
                        photoList.add(userTcPhoto4);
                        Gson gson = new Gson();
                        String strphotoList = gson.toJson(photoList);
                        LogUtils.e("strphotoList", strphotoList);
                        mProgressDialog = new ProgressDialog(CourseDetailsActivity.this, ProgressDialog.THEME_HOLO_DARK);
                        mProgressDialog.setMessage("提交中...");
                        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        mProgressDialog.setCancelable(false);
                        mProgressDialog.show();
                        new Login().getSureCosrseAndLearn1(0, userId, orgId, tcsn, learnsn, 0, courseLength2, 1, photoList, this, 3);
                    }
                }
            } else if (formattime2 < courseLength2 * 60) {//滿一分鐘保存
//                    AlertDialog.Builder builder = new AlertDialog.Builder(this);
//                    View view1 = View
//                            .inflate(CourseDetailsActivity.this, R.layout.diolog_learn_layout, null);
//                    TextView tv_message = (TextView) view1
//                            .findViewById(R.id.message);//输入内容
//                    tv_message.setText("您的学习进度未保存，请点击“保存退出”按钮退出本课程学习，否则下次进入您将重新学习本课程。");
//                    TextView btn_sure = (TextView) view1.findViewById(R.id.positiveButton);
//                    TextView btn_cancel = (TextView) view1.findViewById(R.id.negativeButton);
//                    btn_cancel.setVisibility(View.GONE);
//                    btn_sure.setText("保存退出");
//                    final AlertDialog dialog = builder.create();
//                    dialog.show();
//                    dialog.getWindow().setContentView(view1);
//                    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
//                    dialog.setCancelable(false);
//                    btn_sure.setOnClickListener(new View.OnClickListener() {
//                        @Override
//                        public void onClick(View view) {
//                            dialog.dismiss();
                LoginUserBean userInfo = UserManger.getUserInfo();
                String userId1 = userInfo.getData().getUserId();
                SharedPreferences sp2 = getSharedPreferences("CourseDetailsActivity",
                        Context.MODE_PRIVATE);
//                            String formats1 = sp2.getString("format", "");
//                            String[] splitformat1 = formats1.split(":");
//                            String formatstr1 = splitformat1[0];
//                            String formatstr2 = splitformat1[1];
//                            String formatstr3 = splitformat1[2];
//                            int iformat4 = Integer.valueOf(formatstr1);//转int
//                            int iformat5 = Integer.valueOf(formatstr2);//转int
//                            int iformat6 = Integer.valueOf(formatstr3);//转int
//                            int formattime1 = iformat4 * 3600 + iformat5 * 60 + iformat6 * 1;
                //  String imgurl1 = sp.getString("imgurl", "");
                int learnsn1 = sp2.getInt("learnsn", 0);
                int tcsn1 = sp2.getInt("tcsn", 0);
                String orgId1 = sp2.getString("orgId", "");
                int readLength = (formattime2 % 60 == 0) ? formattime2 / 60 : (formattime2 / 60);//累计学习时间
                //int readLength = (formattime2 % 60 != 0) ? formattime2 / 60+1:(formattime2 / 60);//累计学习时间
                if (photoMark == 1) {

                    LogUtils.e("readLength", readLength + "");
                    String imgurl1 = sp2.getString("imgurl", "");
                    String firsttimestr = sp2.getString("firsttime", "");//第一次抓拍时间
                    List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                    String firsttimesub = firsttimestr.substring(3, 8);//截取字符串00:00:00变成00:00
                    //                     String durationsub = duration.substring(3, 8);//截取字符串00:00:00变成00:00
                    UserTcPhoto userTcPhoto = new UserTcPhoto();
                    userTcPhoto.setSnapTime(firsttimesub);
                    userTcPhoto.setUrl(imgurl1);
                    photoList.add(userTcPhoto);
                    Gson gson = new Gson();
                    String strphotoList = gson.toJson(photoList);
                    LogUtils.e("strphotoList", strphotoList);
                    initsavedata(userId1, orgId1, tcsn1, learnsn1, readLength, photoList);
                } else if (photoMark == 0) {
                    //     int readLength = (formattime1 % 60 == 0) ? formattime1 / 60 : (formattime1 / 60);//累计学习时间
                    LogUtils.e("readLength", readLength + "");
                    String firsttimestr = sp2.getString("firsttime", "");//第一次抓拍时间
                    List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                    String imgurl1 = sp2.getString("imgurl", "");
                    //                     String durationsub = duration.substring(3, 8);//截取字符串00:00:00变成00:00
                    UserTcPhoto userTcPhoto = new UserTcPhoto();
                    userTcPhoto.setSnapTime(firsttimestr);
                    userTcPhoto.setUrl(imgurl1);
                    photoList.add(userTcPhoto);
                    Gson gson = new Gson();
                    String strphotoList = gson.toJson(photoList);
                    LogUtils.e("strphotoList", strphotoList);
                    initsavedata(userId1, orgId1, tcsn1, learnsn1, readLength, photoList);
                } else if (photoMark == 2) {
                    //    int readLength = (formattime1 % 60 == 0) ? formattime1 / 60 : (formattime1 / 60);//累计学习时间
                    LogUtils.e("readLength", readLength + "");
                    String imgurl1 = sp2.getString("imgurl", "");
                    String firsttimestr = sp2.getString("firsttime", "");//第一次抓拍时间
                    String imgurl2 = sp2.getString("imgurl1", "");
                    String numFifthpartstr = sp2.getString("numFifthpartstr", "");//第二次抓拍时间
                    List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                    String firsttimesub = firsttimestr.substring(3, 8);//截取字符串00:00:00变成00:00

                    UserTcPhoto userTcPhoto = new UserTcPhoto();
                    userTcPhoto.setSnapTime(firsttimesub);
                    userTcPhoto.setUrl(imgurl1);
                    photoList.add(userTcPhoto);
                    UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                    if (imgurl2.equals("")) {
                        userTcPhoto1.setSnapTime(numFifthpartstr);
                        userTcPhoto1.setUrl(imgurl2);

                    } else {
                        String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        userTcPhoto1.setSnapTime(numFifthpartstr1);
                        userTcPhoto1.setUrl(imgurl2);
                    }
                    photoList.add(userTcPhoto1);
                    Gson gson = new Gson();
                    String strphotoList = gson.toJson(photoList);
                    LogUtils.e("strphotoList", strphotoList);
                    initsavedata(userId1, orgId1, tcsn1, learnsn1, readLength, photoList);
                } else if (photoMark == 3) {
                    //     int readLength = (formattime1 % 60 == 0) ? formattime1 / 60 : (formattime1 / 60);//累计学习时间
                    LogUtils.e("readLength", readLength + "");
                    String imgurl1 = sp2.getString("imgurl", "");
                    String firsttimestr = sp2.getString("firsttime", "");//第一次抓拍时间
                    String imgurl2 = sp2.getString("imgurl1", "");
                    String numsecondpartstr = sp2.getString("numsecondpartstr", "");//第二次抓拍时间
                    String imgurl3 = sp2.getString("imgurl2", "");
                    String numFifthpartstr = sp2.getString("numFifthpartstr", "");//第三次抓拍时间
                    List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                    String firsttimesub = firsttimestr.substring(3, 8);//截取字符串00:00:00变成00:00

                    UserTcPhoto userTcPhoto = new UserTcPhoto();
                    userTcPhoto.setSnapTime(firsttimesub);
                    userTcPhoto.setUrl(imgurl1);
                    photoList.add(userTcPhoto);
                    UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                    if (imgurl2.equals("")) {
                        userTcPhoto1.setSnapTime(numsecondpartstr);
                        userTcPhoto1.setUrl(imgurl2);

                    } else {
                        String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        userTcPhoto1.setSnapTime(numsecondpartstr1);
                        userTcPhoto1.setUrl(imgurl2);
                    }
                    photoList.add(userTcPhoto1);
                    UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                    if (imgurl3.equals("")) {
                        userTcPhoto2.setSnapTime(numFifthpartstr);
                        userTcPhoto2.setUrl(imgurl3);

                    } else {
                        String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        userTcPhoto2.setSnapTime(numFifthpartstr1);
                        userTcPhoto2.setUrl(imgurl3);
                    }
                    photoList.add(userTcPhoto2);

                    Gson gson = new Gson();
                    String strphotoList = gson.toJson(photoList);
                    LogUtils.e("strphotoList", strphotoList);
                    initsavedata(userId1, orgId1, tcsn1, learnsn1, readLength, photoList);
                } else if (photoMark == 4) {
                    //    int readLength = (formattime1 % 60 == 0) ? formattime1 / 60 : (formattime1 / 60);//累计学习时间
                    LogUtils.e("readLength", readLength + "");
                    String imgurl1 = sp2.getString("imgurl", "");
                    String firsttimestr = sp2.getString("firsttime", "");//第一次抓拍时间
                    String imgurl2 = sp2.getString("imgurl1", "");
                    String numsecondpartstr = sp2.getString("numsecondpartstr", "");//第二次抓拍时间
                    String imgurl3 = sp2.getString("imgurl2", "");
                    String numthirdpartstr = sp2.getString("numthirdpartstr", "");//第三次抓拍时间
                    String imgurl4 = sp2.getString("imgurl3", "");
                    String numFifthpartstr = sp2.getString("numFifthpartstr", "");//第四次抓拍时间
                    List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                    String firsttimesub = firsttimestr.substring(3, 8);//截取字符串00:00:00变成00:00

                    UserTcPhoto userTcPhoto = new UserTcPhoto();
                    userTcPhoto.setSnapTime(firsttimesub);
                    userTcPhoto.setUrl(imgurl1);
                    photoList.add(userTcPhoto);
                    UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                    if (imgurl2.equals("")) {
                        userTcPhoto1.setSnapTime(numsecondpartstr);
                        userTcPhoto1.setUrl(imgurl2);

                    } else {
                        String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        userTcPhoto1.setSnapTime(numsecondpartstr1);
                        userTcPhoto1.setUrl(imgurl2);
                    }
                    photoList.add(userTcPhoto1);
                    UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                    if (imgurl3.equals("")) {
                        userTcPhoto2.setSnapTime(numthirdpartstr);
                        userTcPhoto2.setUrl(imgurl3);

                    } else {
                        String numthirdpartstr1 = numthirdpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        userTcPhoto2.setSnapTime(numthirdpartstr1);
                        userTcPhoto2.setUrl(imgurl3);
                    }
                    photoList.add(userTcPhoto2);
                    UserTcPhoto userTcPhoto3 = new UserTcPhoto();
                    if (imgurl4.equals("")) {
                        userTcPhoto3.setSnapTime(numFifthpartstr);
                        userTcPhoto3.setUrl(imgurl4);

                    } else {
                        String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        userTcPhoto3.setSnapTime(numFifthpartstr1);
                        userTcPhoto3.setUrl(imgurl4);
                    }
                    photoList.add(userTcPhoto3);

                    Gson gson = new Gson();
                    String strphotoList = gson.toJson(photoList);
                    LogUtils.e("strphotoList", strphotoList);
                    initsavedata(userId1, orgId1, tcsn1, learnsn1, readLength, photoList);
                } else if (photoMark == 5) {
                    //    int readLength = (formattime1 % 60 == 0) ? formattime1 / 60 : (formattime1 / 60);//累计学习时间
                    LogUtils.e("readLength", readLength + "");
                    String imgurl1 = sp2.getString("imgurl", "");
                    String firsttimestr = sp2.getString("firsttime", "");//第一次抓拍时间
                    String imgurl2 = sp2.getString("imgurl1", "");
                    String numsecondpartstr = sp2.getString("numsecondpartstr", "");//第二次抓拍时间
                    String imgurl3 = sp2.getString("imgurl2", "");
                    String numthirdpartstr = sp2.getString("numthirdpartstr", "");//第三次抓拍时间
                    String imgurl4 = sp2.getString("imgurl3", "");
                    String numfourpartstr = sp2.getString("numfourpartstr", "");//第四次抓拍时间
                    String imgurl5 = sp2.getString("imgurl4", "");
                    String numFifthpartstr = sp2.getString("numFifthpartstr", "");//第五次抓拍时间
                    List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                    String firsttimesub = firsttimestr.substring(3, 8);//截取字符串00:00:00变成00:00

                    UserTcPhoto userTcPhoto = new UserTcPhoto();
                    userTcPhoto.setSnapTime(firsttimesub);
                    userTcPhoto.setUrl(imgurl1);
                    photoList.add(userTcPhoto);
                    UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                    if (imgurl2.equals("")) {
                        userTcPhoto1.setSnapTime(numsecondpartstr);
                        userTcPhoto1.setUrl(imgurl2);

                    } else {
                        String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        userTcPhoto1.setSnapTime(numsecondpartstr1);
                        userTcPhoto1.setUrl(imgurl2);
                    }
                    photoList.add(userTcPhoto1);
                    UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                    if (imgurl3.equals("")) {
                        userTcPhoto2.setSnapTime(numthirdpartstr);
                        userTcPhoto2.setUrl(imgurl3);

                    } else {
                        String numthirdpartstr1 = numthirdpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        userTcPhoto2.setSnapTime(numthirdpartstr1);
                        userTcPhoto2.setUrl(imgurl3);
                    }
                    photoList.add(userTcPhoto2);
                    UserTcPhoto userTcPhoto3 = new UserTcPhoto();
                    if (imgurl4.equals("")) {
                        userTcPhoto3.setSnapTime(numfourpartstr);
                        userTcPhoto3.setUrl(imgurl4);

                    } else {
                        String numfourpartstr1 = numfourpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        userTcPhoto3.setSnapTime(numfourpartstr1);
                        userTcPhoto3.setUrl(imgurl4);
                    }
                    photoList.add(userTcPhoto3);
                    UserTcPhoto userTcPhoto4 = new UserTcPhoto();
                    if (imgurl5.equals("")) {
                        userTcPhoto4.setSnapTime(numFifthpartstr);
                        userTcPhoto4.setUrl(imgurl5);

                    } else {
                        String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                        userTcPhoto4.setSnapTime(numFifthpartstr1);
                        userTcPhoto4.setUrl(imgurl5);
                    }
                    photoList.add(userTcPhoto4);
                    Gson gson = new Gson();
                    String strphotoList = gson.toJson(photoList);
                    LogUtils.e("strphotoList", strphotoList);
                    initsavedata(userId1, orgId1, tcsn1, learnsn1, readLength, photoList);
                }
//                        }
//                    });

            }
        }

        //   super.onBackPressed();
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (sensorManager != null) {
            sensorManager.unregisterListener(sensorEventListener);
        }
//        JZVideoPlayer jzvd = JZVideoPlayerManager.getCurrentJzvd();
//        if(jzvd!=null)
//        {
//            jzvd.onStatePause();
//            JZMediaManager.pause();//暂停
//
//        }else{
//            JZVideoPlayer.releaseAllVideos();
//
//        }

        Jzvd.resetAllVideos();
        /**
         * 记得释放camera，方便其他应用调用
         */
        releaseCamera();
    }

    //退出后台
    @Override
    protected void onStop() {
        super.onStop();
//        if (timerTask != null) {
//            timerTask.cancel();
//            if(ishave)
//            {
//                ishave =false;
//            }else{
//                ishave =true;
//            }
//        }
    }

    //重启前台
    @Override
    protected void onRestart() {
        super.onRestart();
        if (setYm.equals("")) {

            TiShiDialog.Builder builder1 = new TiShiDialog.Builder(CourseDetailsActivity.this);
            builder1.setMessage("仅查看,不能保存记录");
            builder1.setTitle("提示:");
            builder1.setPositiveButton("确认退出", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    ;
                    SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                            Context.MODE_PRIVATE);
                    SharedPreferences.Editor edit = sp.edit();
                    edit.clear();
                    edit.commit();
//                        LoginUserBean userInfo = UserManger.getUserInfo();
//                        String userId = userInfo.getData().getUserId();
//                        SharedPreferences sp = getSharedPreferences("durationandformat1" + userId,
//                                Context.MODE_PRIVATE);
//                        int otcSn = sp.getInt("otcSn", 0);
//                        int learnsn = sp.getInt("learnsn", 0);
//                        String format = sp.getString("format"+ otcSn+learnsn, "");
//                        String imgurl = sp.getString("imgurl"+ otcSn+learnsn, "");
//                        int tcsn = sp.getInt("tcsn", 0);
//                        int sn = sp.getInt("sn", 0);
//                        String statYm = sp.getString("statYm", "");
//                        String orgId = sp.getString("orgId", "");
//                        String[] splitformat = format.split(":");
//                        String format1 = splitformat[0];
//                        String format2 = splitformat[1];
//                        String format3 = splitformat[2];
//                        int iformat1 = Integer.valueOf(format1);//转int
//                        int iformat2 = Integer.valueOf(format2);//转int
//                        int iformat3 = Integer.valueOf(format3);//转int
//                        int formattime = iformat1 * 3600 + iformat2 * 60 + iformat3 * 1;
//                        int photoMark = sp.getInt("photoMark", 0);
//                        if(photoMark==1)
//                        {
//                            int readLength = (formattime%60==0)?formattime/60:(formattime/60+1);//累计学习时间
//                            LogUtils.e("readLength",readLength+"");
//                            String firsttime = sp.getString("firsttime"+ otcSn, "");//第一次抓拍时间
//                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
//                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
//                            //                     String durationsub = duration.substring(3, 8);//截取字符串00:00:00变成00:00
//                            UserTcPhoto userTcPhoto = new UserTcPhoto();
//                            userTcPhoto.setSnapTime(firsttimesub);
//                            userTcPhoto.setUrl(imgurl);
//                            photoList.add(userTcPhoto);
//                            Gson gson = new Gson();
//                            String strphotoList = gson.toJson(photoList);
//                            LogUtils.e("strphotoList",strphotoList);
//                            initsavedata(sn,userId,orgId,tcsn,otcSn,learnsn,readLength,photoList);
//                        }else if(photoMark==0){
//                            int readLength = (formattime%60==0)?formattime/60:(formattime/60+1);//累计学习时间
//                            LogUtils.e("readLength",readLength+"");
//                            String firsttime = sp.getString("firsttime"+ otcSn, "");//第一次抓拍时间
//                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
//                            //      String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
//                            //                     String durationsub = duration.substring(3, 8);//截取字符串00:00:00变成00:00
//                            UserTcPhoto userTcPhoto = new UserTcPhoto();
//                            userTcPhoto.setSnapTime(firsttime);
//                            userTcPhoto.setUrl(imgurl);
//                            photoList.add(userTcPhoto);
//                            Gson gson = new Gson();
//                            String strphotoList = gson.toJson(photoList);
//                            LogUtils.e("strphotoList",strphotoList);
//                            initsavedata(sn,userId,orgId,tcsn,otcSn,learnsn,readLength,photoList);
//                        }
                    timerTask.cancel();
                    timer1.cancel();
                    timerTask = null;
                    timer1 = null;
                    finish();

                }
            });

            builder1.setNegativeButton("继续学习",
                    new android.content.DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            //     initStopDialog();
                            dialog.dismiss();
                            SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                                    Context.MODE_PRIVATE);
                            SharedPreferences.Editor edit = sp.edit();
                            edit.putInt("tag", 0);
                            edit.commit();
                        }
                    });
            builder1.create().show();
            return;
        }

        SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                Context.MODE_PRIVATE);
        int tag = sp.getInt("tag", 0);
        if (tag == 0) {
            String formats1 = sp.getString("format", "");
            String[] splitformat1 = formats1.split(":");
            String formatstr1 = splitformat1[0];
            String formatstr2 = splitformat1[1];
            String formatstr3 = splitformat1[2];
            int iformat4 = Integer.valueOf(formatstr1);//转int
            int iformat5 = Integer.valueOf(formatstr2);//转int
            int iformat6 = Integer.valueOf(formatstr3);//转int
            int formattime1 = iformat4 * 3600 + iformat5 * 60 + iformat6 * 1;
            if (formattime1 < 60) {
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                View view1 = View.inflate(CourseDetailsActivity.this, R.layout.diolog_learn_layout, null);
                TextView tv_message = (TextView) view1.findViewById(R.id.message);//输入内容
                tv_message.setText("您本次学习未满一分钟，无法保存学习进度，退出后将重新学习本课程。");
                TextView btn_sure = (TextView) view1.findViewById(R.id.positiveButton);
                TextView btn_cancel = (TextView) view1.findViewById(R.id.negativeButton);
                btn_sure.setText("确认退出");
                btn_cancel.setText("继续学习");
                final AlertDialog dialog = builder.create();
                dialog.show();
                dialog.getWindow().setContentView(view1);
                dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                dialog.setCancelable(false);
                btn_sure.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        dialog.dismiss();

                        SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                                Context.MODE_PRIVATE);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.clear();
                        edit.commit();
//                        LoginUserBean userInfo = UserManger.getUserInfo();
//                        String userId = userInfo.getData().getUserId();
//                        SharedPreferences sp = getSharedPreferences("durationandformat1" + userId,
//                                Context.MODE_PRIVATE);
//                        int otcSn = sp.getInt("otcSn", 0);
//                        int learnsn = sp.getInt("learnsn", 0);
//                        String format = sp.getString("format"+ otcSn+learnsn, "");
//                        String imgurl = sp.getString("imgurl"+ otcSn+learnsn, "");
//                        int tcsn = sp.getInt("tcsn", 0);
//                        int sn = sp.getInt("sn", 0);
//                        String statYm = sp.getString("statYm", "");
//                        String orgId = sp.getString("orgId", "");
//                        String[] splitformat = format.split(":");
//                        String format1 = splitformat[0];
//                        String format2 = splitformat[1];
//                        String format3 = splitformat[2];
//                        int iformat1 = Integer.valueOf(format1);//转int
//                        int iformat2 = Integer.valueOf(format2);//转int
//                        int iformat3 = Integer.valueOf(format3);//转int
//                        int formattime = iformat1 * 3600 + iformat2 * 60 + iformat3 * 1;
//                        int photoMark = sp.getInt("photoMark", 0);
//                        if(photoMark==1)
//                        {
//                            int readLength = (formattime%60==0)?formattime/60:(formattime/60+1);//累计学习时间
//                            LogUtils.e("readLength",readLength+"");
//                            String firsttime = sp.getString("firsttime"+ otcSn, "");//第一次抓拍时间
//                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
//                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
//                            //                     String durationsub = duration.substring(3, 8);//截取字符串00:00:00变成00:00
//                            UserTcPhoto userTcPhoto = new UserTcPhoto();
//                            userTcPhoto.setSnapTime(firsttimesub);
//                            userTcPhoto.setUrl(imgurl);
//                            photoList.add(userTcPhoto);
//                            Gson gson = new Gson();
//                            String strphotoList = gson.toJson(photoList);
//                            LogUtils.e("strphotoList",strphotoList);
//                            initsavedata(sn,userId,orgId,tcsn,otcSn,learnsn,readLength,photoList);
//                        }else if(photoMark==0){
//                            int readLength = (formattime%60==0)?formattime/60:(formattime/60+1);//累计学习时间
//                            LogUtils.e("readLength",readLength+"");
//                            String firsttime = sp.getString("firsttime"+ otcSn, "");//第一次抓拍时间
//                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
//                            //      String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
//                            //                     String durationsub = duration.substring(3, 8);//截取字符串00:00:00变成00:00
//                            UserTcPhoto userTcPhoto = new UserTcPhoto();
//                            userTcPhoto.setSnapTime(firsttime);
//                            userTcPhoto.setUrl(imgurl);
//                            photoList.add(userTcPhoto);
//                            Gson gson = new Gson();
//                            String strphotoList = gson.toJson(photoList);
//                            LogUtils.e("strphotoList",strphotoList);
//                            initsavedata(sn,userId,orgId,tcsn,otcSn,learnsn,readLength,photoList);
//                        }
                        timerTask.cancel();
                        timer1.cancel();
                        timerTask = null;
                        timer1 = null;
                        finish();
                        //设置你的操作事项
                    }
                });

                btn_cancel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {


//                                LoginUserBean userInfo = UserManger.getUserInfo();
//                                String userId = userInfo.getData().getUserId();
//                                SharedPreferences sp = getSharedPreferences("durationandformat1"+userId,
//                                        Context.MODE_PRIVATE);
//                                int photoMark = sp.getInt("photoMark", 0);
//                                if(photoMark==1)
//                                {
//                                    Thread thread = new Thread(new Runnable() {
//                                        @Override
//                                        public void run() {
//                                            //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
//                                            mHandler.sendEmptyMessage(0);
//                                        }
//                                    });
//                                    thread.start();
//                                }else if(photoMark==0){
//                                    Thread thread = new Thread(new Runnable() {
//                                        @Override
//                                        public void run() {
//                                            //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
//                                            mHandler.sendEmptyMessage(2);
//                                        }
//                                    });
//                                    thread.start();
//                                }
                        //      tv_pause.setText("继续学习");
//                            LoginUserBean userInfo = UserManger.getUserInfo();
//                            String userId = userInfo.getData().getUserId();
//                            SharedPreferences sp = getSharedPreferences("durationandformat1" + userId,
//                                    Context.MODE_PRIVATE);
//                            int photoMark = sp.getInt("photoMark", 0);
//                            if (photoMark == 1) {
//                                Thread thread = new Thread(new Runnable() {
//                                    @Override
//                                    public void run() {
//                                        //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
//                                        mHandler.sendEmptyMessage(0);
//                                    }
//                                });
//                                thread.start();
//                            } else if (photoMark == 0) {
//                                Thread thread = new Thread(new Runnable() {
//                                    @Override
//                                    public void run() {
//                                        //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
//                                        mHandler.sendEmptyMessage(2);
//                                    }
//                                });
//                                thread.start();
//                            }
                        dialog.dismiss();
                        SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                                Context.MODE_PRIVATE);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putInt("tag", 0);
                        edit.commit();
                    }
                });

            } else {
                //滿一分鐘保存
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                View view1 = View.inflate(CourseDetailsActivity.this, R.layout.diolog_learn_layout, null);
                TextView tv_message = (TextView) view1.findViewById(R.id.message);//输入内容
                tv_message.setText("您的学习进度已保存，下次进入将继续本课程的学习。");
                TextView btn_sure = (TextView) view1.findViewById(R.id.positiveButton);
                TextView btn_cancel = (TextView) view1.findViewById(R.id.negativeButton);
                btn_sure.setText("确认退出");
                btn_cancel.setText("继续学习");
                final AlertDialog dialog = builder.create();
                dialog.show();
                dialog.getWindow().setContentView(view1);
                dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                dialog.setCancelable(false);
                btn_sure.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        dialog.dismiss();
                        LoginUserBean userInfo = UserManger.getUserInfo();
                        String userId1 = userInfo.getData().getUserId();
                        SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                                Context.MODE_PRIVATE);
                        String formats1 = sp.getString("format", "");
                        String[] splitformat1 = formats1.split(":");
                        String formatstr1 = splitformat1[0];
                        String formatstr2 = splitformat1[1];
                        String formatstr3 = splitformat1[2];
                        int iformat4 = Integer.valueOf(formatstr1);//转int
                        int iformat5 = Integer.valueOf(formatstr2);//转int
                        int iformat6 = Integer.valueOf(formatstr3);//转int
                        int formattime1 = iformat4 * 3600 + iformat5 * 60 + iformat6 * 1;
                        int tcsn1 = sp.getInt("tcsn", 0);
                        int learnsn1 = sp.getInt("learnsn", 0);
                        //  int sn1 = sp.getInt("sn", 0);
                        String orgId1 = sp.getString("orgId", "");
                        //    int readLength = (formattime1 % 60 != 0) ? formattime1 / 60+1 : (formattime1 / 60);//累计学习时间
                        int readLength = (formattime1 % 60 == 0) ? formattime1 / 60 : (formattime1 / 60);//累计学习时间
                        if (photoMark == 1) {
                            String imgurl1 = sp.getString("imgurl", "");
                            //  int readLength = (formattime1 % 60 == 0) ? formattime1 / 60 : (formattime1 / 60);//累计学习时间
                            LogUtils.e("readLength", readLength + "");
                            String firsttime = sp.getString("firsttime", "");//第一次抓拍时间
                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                            //                     String durationsub = duration.substring(3, 8);//截取字符串00:00:00变成00:00
                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                            userTcPhoto.setSnapTime(firsttimesub);
                            userTcPhoto.setUrl(imgurl1);
                            photoList.add(userTcPhoto);
                            Gson gson = new Gson();
                            String strphotoList = gson.toJson(photoList);
                            LogUtils.e("strphotoList", strphotoList);
                            initsavedata(userId1, orgId1, tcsn1, learnsn1, readLength, photoList);
                        } else if (photoMark == 0) {
                            String imgurl1 = sp.getString("imgurl", "");
                            //    int readLength = (formattime1 % 60 == 0) ? formattime1 / 60 : (formattime1 / 60);//累计学习时间
                            LogUtils.e("readLength", readLength + "");
                            String firsttime = sp.getString("firsttime", "");//第一次抓拍时间
                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                            //      String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00
                            //                     String durationsub = duration.substring(3, 8);//截取字符串00:00:00变成00:00
                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                            userTcPhoto.setSnapTime(firsttime);
                            userTcPhoto.setUrl(imgurl1);
                            photoList.add(userTcPhoto);
                            Gson gson = new Gson();
                            String strphotoList = gson.toJson(photoList);
                            LogUtils.e("strphotoList", strphotoList);
                            initsavedata(userId1, orgId1, tcsn1, learnsn1, readLength, photoList);
                        } else if (photoMark == 2) {
                            //    int readLength = (formattime1 % 60 == 0) ? formattime1 / 60 : (formattime1 / 60);//累计学习时间
                            LogUtils.e("readLength", readLength + "");
                            String imgurl1 = sp.getString("imgurl", "");
                            String firsttime = sp.getString("firsttime", "");//第一次抓拍时间
                            String imgurl2 = sp.getString("imgurl1", "");
                            String numFifthpartstr = sp.getString("numFifthpartstr", "");//第二次抓拍时间
                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00

                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                            userTcPhoto.setSnapTime(firsttimesub);
                            userTcPhoto.setUrl(imgurl1);
                            photoList.add(userTcPhoto);
                            UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                            if (imgurl2.equals("")) {
                                userTcPhoto1.setSnapTime(numFifthpartstr);
                                userTcPhoto1.setUrl(imgurl2);

                            } else {
                                String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                                userTcPhoto1.setSnapTime(numFifthpartstr1);
                                userTcPhoto1.setUrl(imgurl2);
                            }
                            photoList.add(userTcPhoto1);
                            Gson gson = new Gson();
                            String strphotoList = gson.toJson(photoList);
                            LogUtils.e("strphotoList", strphotoList);
                            initsavedata(userId1, orgId1, tcsn1, learnsn1, readLength, photoList);
                        } else if (photoMark == 3) {
                            //   int readLength = (formattime1 % 60 == 0) ? formattime1 / 60 : (formattime1 / 60);//累计学习时间
                            LogUtils.e("readLength", readLength + "");
                            String imgurl1 = sp.getString("imgurl", "");
                            String firsttime = sp.getString("firsttime", "");//第一次抓拍时间
                            String imgurl2 = sp.getString("imgurl1", "");
                            String numsecondpartstr = sp.getString("numsecondpartstr", "");//第二次抓拍时间
                            String imgurl3 = sp.getString("imgurl2", "");
                            String numFifthpartstr = sp.getString("numFifthpartstr", "");//第三次抓拍时间
                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00

                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                            userTcPhoto.setSnapTime(firsttimesub);
                            userTcPhoto.setUrl(imgurl1);
                            photoList.add(userTcPhoto);
                            UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                            if (imgurl2.equals("")) {
                                userTcPhoto1.setSnapTime(numsecondpartstr);
                                userTcPhoto1.setUrl(imgurl2);

                            } else {
                                String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                                userTcPhoto1.setSnapTime(numsecondpartstr1);
                                userTcPhoto1.setUrl(imgurl2);
                            }
                            photoList.add(userTcPhoto1);
                            UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                            if (imgurl3.equals("")) {
                                userTcPhoto2.setSnapTime(numFifthpartstr);
                                userTcPhoto2.setUrl(imgurl3);

                            } else {
                                String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                                userTcPhoto2.setSnapTime(numFifthpartstr1);
                                userTcPhoto2.setUrl(imgurl3);
                            }
                            photoList.add(userTcPhoto2);

                            Gson gson = new Gson();
                            String strphotoList = gson.toJson(photoList);
                            LogUtils.e("strphotoList", strphotoList);
                            initsavedata(userId1, orgId1, tcsn1, learnsn1, readLength, photoList);
                        } else if (photoMark == 4) {
                            //    int readLength = (formattime1 % 60 == 0) ? formattime1 / 60 : (formattime1 / 60);//累计学习时间
                            LogUtils.e("readLength", readLength + "");
                            String imgurl1 = sp.getString("imgurl", "");
                            String firsttime = sp.getString("firsttime", "");//第一次抓拍时间
                            String imgurl2 = sp.getString("imgurl1", "");
                            String numsecondpartstr = sp.getString("numsecondpartstr", "");//第二次抓拍时间
                            String imgurl3 = sp.getString("imgurl2", "");
                            String numthirdpartstr = sp.getString("numthirdpartstr", "");//第三次抓拍时间
                            String imgurl4 = sp.getString("imgurl3", "");
                            String numFifthpartstr = sp.getString("numFifthpartstr", "");//第四次抓拍时间
                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00

                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                            userTcPhoto.setSnapTime(firsttimesub);
                            userTcPhoto.setUrl(imgurl1);
                            photoList.add(userTcPhoto);
                            UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                            if (imgurl2.equals("")) {
                                userTcPhoto1.setSnapTime(numsecondpartstr);
                                userTcPhoto1.setUrl(imgurl2);

                            } else {
                                String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                                userTcPhoto1.setSnapTime(numsecondpartstr1);
                                userTcPhoto1.setUrl(imgurl2);
                            }
                            photoList.add(userTcPhoto1);
                            UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                            if (imgurl3.equals("")) {
                                userTcPhoto2.setSnapTime(numthirdpartstr);
                                userTcPhoto2.setUrl(imgurl3);

                            } else {
                                String numthirdpartstr1 = numthirdpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                                userTcPhoto2.setSnapTime(numthirdpartstr1);
                                userTcPhoto2.setUrl(imgurl3);
                            }
                            photoList.add(userTcPhoto2);
                            UserTcPhoto userTcPhoto3 = new UserTcPhoto();
                            if (imgurl4.equals("")) {
                                userTcPhoto3.setSnapTime(numFifthpartstr);
                                userTcPhoto3.setUrl(imgurl4);

                            } else {
                                String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                                userTcPhoto3.setSnapTime(numFifthpartstr1);
                                userTcPhoto3.setUrl(imgurl4);
                            }
                            photoList.add(userTcPhoto3);

                            Gson gson = new Gson();
                            String strphotoList = gson.toJson(photoList);
                            LogUtils.e("strphotoList", strphotoList);
                            initsavedata(userId1, orgId1, tcsn1, learnsn1, readLength, photoList);
                        } else if (photoMark == 5) {
                            //    int readLength = (formattime1 % 60 == 0) ? formattime1 / 60 : (formattime1 / 60);//累计学习时间
                            LogUtils.e("readLength", readLength + "");
                            String imgurl1 = sp.getString("imgurl", "");
                            String firsttime = sp.getString("firsttime", "");//第一次抓拍时间
                            String imgurl2 = sp.getString("imgurl1", "");
                            String numsecondpartstr = sp.getString("numsecondpartstr", "");//第二次抓拍时间
                            String imgurl3 = sp.getString("imgurl2", "");
                            String numthirdpartstr = sp.getString("numthirdpartstr", "");//第三次抓拍时间
                            String imgurl4 = sp.getString("imgurl3", "");
                            String numfourpartstr = sp.getString("numfourpartstr", "");//第四次抓拍时间
                            String imgurl5 = sp.getString("imgurl4", "");
                            String numFifthpartstr = sp.getString("numFifthpartstr", "");//第五次抓拍时间
                            List<UserTcPhoto> photoList = new ArrayList<UserTcPhoto>();
                            String firsttimesub = firsttime.substring(3, 8);//截取字符串00:00:00变成00:00

                            UserTcPhoto userTcPhoto = new UserTcPhoto();
                            userTcPhoto.setSnapTime(firsttimesub);
                            userTcPhoto.setUrl(imgurl1);
                            photoList.add(userTcPhoto);
                            UserTcPhoto userTcPhoto1 = new UserTcPhoto();
                            if (imgurl2.equals("")) {
                                userTcPhoto1.setSnapTime(numsecondpartstr);
                                userTcPhoto1.setUrl(imgurl2);

                            } else {
                                String numsecondpartstr1 = numsecondpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                                userTcPhoto1.setSnapTime(numsecondpartstr1);
                                userTcPhoto1.setUrl(imgurl2);
                            }
                            photoList.add(userTcPhoto1);
                            UserTcPhoto userTcPhoto2 = new UserTcPhoto();
                            if (imgurl3.equals("")) {
                                userTcPhoto2.setSnapTime(numthirdpartstr);
                                userTcPhoto2.setUrl(imgurl3);

                            } else {
                                String numthirdpartstr1 = numthirdpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                                userTcPhoto2.setSnapTime(numthirdpartstr1);
                                userTcPhoto2.setUrl(imgurl3);
                            }
                            photoList.add(userTcPhoto2);
                            UserTcPhoto userTcPhoto3 = new UserTcPhoto();
                            if (imgurl4.equals("")) {
                                userTcPhoto3.setSnapTime(numfourpartstr);
                                userTcPhoto3.setUrl(imgurl4);

                            } else {
                                String numfourpartstr1 = numfourpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                                userTcPhoto3.setSnapTime(numfourpartstr1);
                                userTcPhoto3.setUrl(imgurl4);
                            }
                            photoList.add(userTcPhoto3);
                            UserTcPhoto userTcPhoto4 = new UserTcPhoto();
                            if (imgurl5.equals("")) {
                                userTcPhoto4.setSnapTime(numFifthpartstr);
                                userTcPhoto4.setUrl(imgurl5);

                            } else {
                                String numFifthpartstr1 = numFifthpartstr.substring(3, 8);//截取字符串00:00:00变成00:00
                                userTcPhoto4.setSnapTime(numFifthpartstr1);
                                userTcPhoto4.setUrl(imgurl5);
                            }
                            photoList.add(userTcPhoto4);
                            Gson gson = new Gson();
                            String strphotoList = gson.toJson(photoList);
                            LogUtils.e("strphotoList", strphotoList);
                            initsavedata(userId1, orgId1, tcsn1, learnsn1, readLength, photoList);
                        }
                        //设置你的操作事项
                    }
                });

                btn_cancel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {


//                                LoginUserBean userInfo = UserManger.getUserInfo();
//                                String userId = userInfo.getData().getUserId();
//                                SharedPreferences sp = getSharedPreferences("durationandformat1"+userId,
//                                        Context.MODE_PRIVATE);
//                                int photoMark = sp.getInt("photoMark", 0);
//                                if(photoMark==1)
//                                {
//                                    Thread thread = new Thread(new Runnable() {
//                                        @Override
//                                        public void run() {
//                                            //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
//                                            mHandler.sendEmptyMessage(0);
//                                        }
//                                    });
//                                    thread.start();
//                                }else if(photoMark==0){
//                                    Thread thread = new Thread(new Runnable() {
//                                        @Override
//                                        public void run() {
//                                            //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
//                                            mHandler.sendEmptyMessage(2);
//                                        }
//                                    });
//                                    thread.start();
//                                }
                        //      tv_pause.setText("继续学习");
//                            LoginUserBean userInfo = UserManger.getUserInfo();
//                            String userId = userInfo.getData().getUserId();
//                            SharedPreferences sp = getSharedPreferences("durationandformat1" + userId,
//                                    Context.MODE_PRIVATE);
//                            int photoMark = sp.getInt("photoMark", 0);
//                            if (photoMark == 1) {
//                                Thread thread = new Thread(new Runnable() {
//                                    @Override
//                                    public void run() {
//                                        //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
//                                        mHandler.sendEmptyMessage(0);
//                                    }
//                                });
//                                thread.start();
//                            } else if (photoMark == 0) {
//                                Thread thread = new Thread(new Runnable() {
//                                    @Override
//                                    public void run() {
//                                        //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
//                                        mHandler.sendEmptyMessage(2);
//                                    }
//                                });
//                                thread.start();
//                            }
                        dialog.dismiss();
                        SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                                Context.MODE_PRIVATE);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putInt("tag", 0);
                        edit.commit();
                    }
                });

            }
        } else {
            SharedPreferences.Editor edit = sp.edit();
            edit.putInt("tag", 0);
            edit.commit();
        }


//        SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
//                Context.MODE_PRIVATE);
//        int tag = sp.getInt("tag", 0);
//        if (tag == 1) {
//            //tv_pause.setVisibility(View.VISIBLE);
//           // tv_pause.setText("暂停学习");
//            SharedPreferences.Editor edit = sp.edit();
//            edit.putInt("tag", 0);
//            edit.commit();
//            ishave =false;
//        } else if (tag == 0) {
//            String formatime = sp.getString("format", "");
//            String firsttime = sp.getString("firsttime", "");
//            if(!firsttime.equals("")) {
//                String[] splitformat = formatime.split(":");
//                String formatstr1 = splitformat[0];
//                String formatstr2 = splitformat[1];
//                String formatstr3 = splitformat[2];
//                int iformat1 = Integer.valueOf(formatstr1);//转int
//                int iformat2 = Integer.valueOf(formatstr2);//转int
//                int iformat3 = Integer.valueOf(formatstr3);//转int
//                int formattime1 = iformat1 * 3600 + iformat2 * 60 + iformat3 * 1;
//                String[] splitformat1 = firsttime.split(":");
//                String formatstr4 = splitformat1[0];
//                String formatstr5 = splitformat1[1];
//                String formatstr6 = splitformat1[2];
//                int iformat4 = Integer.valueOf(formatstr4);//转int
//                int iformat5 = Integer.valueOf(formatstr5);//转int
//                int iformat6 = Integer.valueOf(formatstr6);//转int
//                int firsttime1 = (iformat4 * 3600 + iformat5 * 60 + iformat6 * 1);
//                if (formattime1 != firsttime1) {
//                    if (ishave) {
//                        initStopDialog();
//                        ishave = true;
//                    } else {
//                        ishave = true;
//                    }
//                } else {
//                    //  tv_pause.setVisibility(View.GONE);
//                }
//            }else{
//                if (ishave) {
//                    initStopDialog();
//                    ishave = true;
//                } else {
//                    ishave = true;
//                }
//            }
//        }else if(tag == 2)
//        {
//            SharedPreferences.Editor edit = sp.edit();
//            edit.putInt("tag", 3);
//            edit.commit();
//            ishave=false;
//        }else if(tag == 3)
//        {
//            if(ishave)
//            {
//                // initStopDialog();
//                ishave =true;
//            }else{
//                ishave =true;
//            }
//
//        }
    }


    @Override
    public void onStart() {
        super.onStart();
        if (this.checkCameraHardware(this) && (mCamera == null)) {
            // 打开camera
            mCamera = getCamera();
            if (mHolder != null) {
                setStartPreview(mCamera, mHolder);
            }
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        //摄像头
        int cameraCount = 1;
        Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
        cameraCount = Camera.getNumberOfCameras();// 得到摄像头的个数

        for (int i = 0; i < cameraCount; i++) {
            Camera.getCameraInfo(i, cameraInfo);// 得到每一个摄像头的信息
            // 现在是后置，变更为前置
            if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
                /**
                 * 记得释放camera，方便其他应用调用
                 */
                releaseCamera();
                // 打开当前选中的摄像头
                mCamera = Camera.open(i);
                //   mCamera.setDisplayOrientation(90);//旋转度数
                // 通过surfaceview显示取景画面
                setStartPreview(mCamera, mHolder);

            }
        }


    }

    private Camera getCamera() {
        Camera camera = null;
        try {
            camera = Camera.open();
        } catch (Exception e) {
            // Camera is not available (in use or does not exist)
            camera = null;
            LogUtils.e(TAG, "Camera is not available (in use or does not exist)");
        }
        return camera;
    }


    @Override
    public void onDestroy() {
        super.onDestroy();

        FileParseUtil.releaseFileView();

        if (mPopWindow != null) {
            mPopWindow.dismiss();
        }
        if (mSorryPopWindow != null) {

            mSorryPopWindow.dismiss();
        }
        if (mStopPopWindow != null) {

            mStopPopWindow.dismiss();
        }
        if (mProgressDialog != null) {
            mProgressDialog.dismiss();
            mProgressDialog = null;
        }
        mHandler.removeCallbacksAndMessages(null);
        mOffHandler.removeCallbacksAndMessages(null);
        EventBus.getDefault().unregister(this);//反注册EventBus
        musicHandler.removeMessages(0);//语音播放器释放
        mediaPlayer.release();//语音播放器释放资源
        SharedPreferences sp = getSharedPreferences("CameraSwitchView",
                Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.commit();
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainThread(MessageEvent event) {
        String imgurl = event.getMessage();
        String messageurl = event.getMessageurl();
        boolean isphoto = event.isIsphoto();
        int code = event.getCode();
        int faceRecgMark = event.getFaceRecgMark();
        String msg = event.getMsg();
        if (faceRecgMark == 1 || faceRecgMark == 2) {
            if (isphoto) {
                Toasty.success(this, "人脸识别成功！", Toast.LENGTH_SHORT, true).show();
                SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                        Context.MODE_PRIVATE);
                if (photoMark == 1) {
                    re_course1.setVisibility(View.GONE);
                    show_camera_iv.setWillNotDraw(false);
                    show_camera_iv.setContentDescription(messageurl);
                    Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(messageurl);
                    show_camera_iv.setImageBitmap(bitmapByUrl);
                    SharedPreferences.Editor edit = sp.edit();
                    edit.putString("imgurl", imgurl);
                    edit.commit();
                } else if (photoMark == 2) {
                    re_course1.setVisibility(View.GONE);
                    if (show_camera_iv.getDrawable() == null) {
                        show_camera_iv.setWillNotDraw(false);
                        show_camera_iv.setContentDescription(messageurl);
                        Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(messageurl);
                        show_camera_iv.setImageBitmap(bitmapByUrl);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl", imgurl);
                        edit.commit();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() == null) {
                        show_camera_iv1.setWillNotDraw(false);
                        show_camera_iv1.setContentDescription(messageurl);
                        Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(messageurl);
                        show_camera_iv1.setImageBitmap(bitmapByUrl);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl1", imgurl);
                        edit.commit();
                    }
                } else if (photoMark == 3) {
                    re_course1.setVisibility(View.GONE);
                    if (show_camera_iv.getDrawable() == null) {
                        show_camera_iv.setWillNotDraw(false);
                        show_camera_iv.setContentDescription(messageurl);
                        Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(messageurl);
                        show_camera_iv.setImageBitmap(bitmapByUrl);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl", imgurl);
                        edit.commit();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() == null) {
                        show_camera_iv1.setWillNotDraw(false);
                        show_camera_iv1.setContentDescription(messageurl);
                        Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(messageurl);
                        show_camera_iv1.setImageBitmap(bitmapByUrl);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl1", imgurl);
                        edit.commit();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() != null && show_camera_iv2.getDrawable() == null) {
                        show_camera_iv2.setWillNotDraw(false);
                        show_camera_iv2.setContentDescription(messageurl);
                        Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(messageurl);
                        show_camera_iv2.setImageBitmap(bitmapByUrl);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl2", imgurl);
                        edit.commit();
                    }
                } else if (photoMark == 4) {
                    if (show_camera_iv.getDrawable() == null) {
                        re_course1.setVisibility(View.GONE);
                        show_camera_iv.setWillNotDraw(false);
                        show_camera_iv.setContentDescription(messageurl);
                        Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(messageurl);
                        show_camera_iv.setImageBitmap(bitmapByUrl);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl", imgurl);
                        edit.commit();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() == null) {
                        re_course1.setVisibility(View.GONE);
                        show_camera_iv1.setWillNotDraw(false);
                        show_camera_iv1.setContentDescription(messageurl);
                        Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(messageurl);
                        show_camera_iv1.setImageBitmap(bitmapByUrl);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl1", imgurl);
                        edit.commit();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() != null && show_camera_iv2.getDrawable() == null) {
                        re_course1.setVisibility(View.GONE);
                        show_camera_iv2.setWillNotDraw(false);
                        show_camera_iv2.setContentDescription(messageurl);
                        Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(messageurl);
                        show_camera_iv2.setImageBitmap(bitmapByUrl);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl2", imgurl);
                        edit.commit();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() != null && show_camera_iv2.getDrawable() != null && show_camera_iv3.getDrawable() == null) {
                        re_course1.setVisibility(View.VISIBLE);
                        show_camera_iv3.setWillNotDraw(false);
                        show_camera_iv3.setContentDescription(messageurl);
                        Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(messageurl);
                        show_camera_iv3.setImageBitmap(bitmapByUrl);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl3", imgurl);
                        edit.commit();
                    }
                } else if (photoMark == 5) {
                    if (show_camera_iv.getDrawable() == null) {
                        re_course1.setVisibility(View.GONE);
                        show_camera_iv.setWillNotDraw(false);
                        show_camera_iv.setContentDescription(messageurl);
                        Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(messageurl);
                        show_camera_iv.setImageBitmap(bitmapByUrl);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl", imgurl);
                        edit.commit();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() == null) {
                        re_course1.setVisibility(View.GONE);
                        show_camera_iv1.setWillNotDraw(false);
                        show_camera_iv1.setContentDescription(messageurl);
                        Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(messageurl);
                        show_camera_iv1.setImageBitmap(bitmapByUrl);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl1", imgurl);
                        edit.commit();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() != null && show_camera_iv2.getDrawable() == null) {
                        re_course1.setVisibility(View.GONE);
                        show_camera_iv2.setWillNotDraw(false);
                        show_camera_iv2.setContentDescription(messageurl);
                        Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(messageurl);
                        show_camera_iv2.setImageBitmap(bitmapByUrl);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl2", imgurl);
                        edit.commit();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() != null && show_camera_iv2.getDrawable() != null && show_camera_iv3.getDrawable() == null) {
                        re_course1.setVisibility(View.VISIBLE);
                        show_camera_iv3.setWillNotDraw(false);
                        show_camera_iv3.setContentDescription(messageurl);
                        Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(messageurl);
                        show_camera_iv3.setImageBitmap(bitmapByUrl);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl3", imgurl);
                        edit.commit();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() != null && show_camera_iv2.getDrawable() != null && show_camera_iv3.getDrawable() != null && show_camera_iv4.getDrawable() == null) {
                        re_course1.setVisibility(View.VISIBLE);
                        show_camera_iv4.setWillNotDraw(false);
                        show_camera_iv4.setContentDescription(messageurl);
                        Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(messageurl);
                        show_camera_iv4.setImageBitmap(bitmapByUrl);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl4", imgurl);
                        edit.commit();
                    }
                }
            } else {

                SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                        Context.MODE_PRIVATE);
                if (photoMark == 1) {
                    re_course1.setVisibility(View.GONE);
                    show_camera_iv.setWillNotDraw(true);
                    SharedPreferences.Editor edit = sp.edit();
                    edit.putString("imgurl", "");
                    edit.commit();
                } else if (photoMark == 2) {
                    re_course1.setVisibility(View.GONE);
                    if (show_camera_iv.getDrawable() == null) {
                        show_camera_iv.setWillNotDraw(true);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl", "");
                        edit.commit();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() == null) {
                        show_camera_iv1.setWillNotDraw(true);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl1", "");
                        edit.commit();
                    }
                } else if (photoMark == 3) {
                    re_course1.setVisibility(View.GONE);
                    if (show_camera_iv.getDrawable() == null) {
                        show_camera_iv.setWillNotDraw(true);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl", "");
                        edit.commit();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() == null) {
                        show_camera_iv1.setWillNotDraw(true);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl1", "");
                        edit.commit();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() != null && show_camera_iv2.getDrawable() == null) {
                        show_camera_iv2.setWillNotDraw(true);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl2", "");
                        edit.commit();
                    }
                } else if (photoMark == 4) {
                    if (show_camera_iv.getDrawable() == null) {
                        re_course1.setVisibility(View.GONE);
                        show_camera_iv.setWillNotDraw(true);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl", "");
                        edit.commit();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() == null) {
                        re_course1.setVisibility(View.GONE);
                        show_camera_iv1.setWillNotDraw(true);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl1", "");
                        edit.commit();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() != null && show_camera_iv2.getDrawable() == null) {
                        re_course1.setVisibility(View.GONE);
                        show_camera_iv2.setWillNotDraw(true);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl2", "");
                        edit.commit();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() != null && show_camera_iv2.getDrawable() != null && show_camera_iv3.getDrawable() == null) {
                        re_course1.setVisibility(View.VISIBLE);
                        show_camera_iv3.setWillNotDraw(true);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl3", "");
                        edit.commit();
                    }
                } else if (photoMark == 5) {
                    if (show_camera_iv.getDrawable() == null) {
                        re_course1.setVisibility(View.GONE);
                        show_camera_iv.setWillNotDraw(true);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl", "");
                        edit.commit();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() == null) {
                        re_course1.setVisibility(View.GONE);
                        show_camera_iv1.setWillNotDraw(true);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl1", "");
                        edit.commit();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() != null && show_camera_iv2.getDrawable() == null) {
                        re_course1.setVisibility(View.GONE);
                        show_camera_iv2.setWillNotDraw(true);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl2", "");
                        edit.commit();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() != null && show_camera_iv2.getDrawable() != null && show_camera_iv3.getDrawable() == null) {
                        re_course1.setVisibility(View.VISIBLE);
                        show_camera_iv3.setWillNotDraw(true);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl3", "");
                        edit.commit();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() != null && show_camera_iv2.getDrawable() != null && show_camera_iv3.getDrawable() != null && show_camera_iv4.getDrawable() == null) {
                        re_course1.setVisibility(View.VISIBLE);
                        show_camera_iv4.setWillNotDraw(true);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl4", "");
                        edit.commit();
                    }
                }
                if (code == 1) {
                    timerTask.cancel();
                    timer1.cancel();
                    timerTask = null;
                    timer1 = null;
                    AlertDialog.Builder builder = new AlertDialog.Builder(this);
                    View view = View
                            .inflate(CourseDetailsActivity.this, R.layout.diolog_learn_layout, null);
                    TextView tv_message = (TextView) view
                            .findViewById(R.id.message);//输入内容
                    tv_message.setText("非常抱歉，您还没有上传个人头像，我们无法对您对你进行人脸识别。");
                    TextView btn_sure = (TextView) view.findViewById(R.id.positiveButton);
                    TextView btn_cancel = (TextView) view.findViewById(R.id.negativeButton);
                    btn_cancel.setVisibility(View.GONE);
                    btn_sure.setText("确定");
                    final AlertDialog dialog = builder.create();
                    dialog.show();
                    dialog.getWindow().setContentView(view);
                    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                    dialog.setCancelable(false);
                    btn_sure.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            dialog.dismiss();
                            SharedPreferences sp1 = getSharedPreferences("CourseDetailsActivity",
                                    Context.MODE_PRIVATE);
                            SharedPreferences.Editor edit = sp1.edit();
                            edit.clear();
                            edit.commit();
                            finish();
                        }
                    });
                } else if (code == 2) {
                    timerTask.cancel();
                    timer1.cancel();
                    timerTask = null;
                    timer1 = null;
                    AlertDialog.Builder builder = new AlertDialog.Builder(this);
                    View view = View
                            .inflate(CourseDetailsActivity.this, R.layout.diolog_learn_layout, null);
                    TextView tv_message = (TextView) view
                            .findViewById(R.id.message);//输入内容
                    tv_message.setText("非常抱歉。系统正在进行维护，请您稍后再进行学习。");
                    TextView btn_sure = (TextView) view.findViewById(R.id.positiveButton);
                    TextView btn_cancel = (TextView) view.findViewById(R.id.negativeButton);
                    btn_cancel.setVisibility(View.GONE);
                    btn_sure.setText("确定");
                    final AlertDialog dialog = builder.create();
                    dialog.show();
                    dialog.getWindow().setContentView(view);
                    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                    dialog.setCancelable(false);
                    btn_sure.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            dialog.dismiss();
                            SharedPreferences sp1 = getSharedPreferences("CourseDetailsActivity",
                                    Context.MODE_PRIVATE);
                            SharedPreferences.Editor edit = sp1.edit();
                            edit.clear();
                            edit.commit();
                            finish();
                        }
                    });
                }
//                else if(code==3)
//                {
//                    timerTask.cancel();
//                    AlertDialog.Builder builder = new AlertDialog.Builder(this);
//                    View view = View
//                            .inflate(CourseDetailsActivity.this, R.layout.diolog_learn_person_layout, null);
//                    TextView btn_sure = (TextView) view.findViewById(R.id.positiveButton);
//                    TextView btn_cancel = (TextView) view.findViewById(R.id.negativeButton);
//                    TextView btn_title = (TextView) view.findViewById(R.id.title);
//                    TextView btn_message = (TextView) view.findViewById(R.id.message);
//                    btn_title.setVisibility(View.VISIBLE);
//                    btn_cancel.setText("我的头像");
//                    btn_message.setText("请确保拍照面部完整，五官清晰，如您多次人脸失败，请在“我的头像”中检查您的个人头像是否正常且且清晰。");
//                    final AlertDialog dialog = builder.create();
//                    dialog.show();
//                    dialog.getWindow().setContentView(view);
//                    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
//                    dialog.setCancelable(false);
//                    btn_sure.setOnClickListener(new View.OnClickListener() {
//                        @Override
//                        public void onClick(View view) {
//                            dialog.dismiss();
//                            SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
//                                    Context.MODE_PRIVATE);
//                            int faceRecgMark = sp.getInt("faceRecgMark", 0);
//                            String photoUrl = sp.getString("photoUrl", "");
//                            Bundle bundle = new Bundle();
//                            bundle.putInt("faceRecgMark", faceRecgMark);
//                            bundle.putString("photoUrl",photoUrl);
//                            startActivityForResult(TakefacePhotoActivity.class,bundle, 0);
//
//                        }
//                    });
//                    btn_cancel.setOnClickListener(new View.OnClickListener() {
//                        @Override
//                        public void onClick(View view) {
//                            dialog.dismiss();
//                            showTakePhotoPopupWindow();
//                        }
//                    });
//                }
                else {
                    timerTask.cancel();
                    AlertDialog.Builder builder = new AlertDialog.Builder(this);
                    View view = View
                            .inflate(CourseDetailsActivity.this, R.layout.diolog_learn_person_layout, null);
                    TextView btn_sure = (TextView) view.findViewById(R.id.positiveButton);
                    TextView btn_cancel = (TextView) view.findViewById(R.id.negativeButton);
                    TextView btn_title = (TextView) view.findViewById(R.id.title);
                    TextView btn_message = (TextView) view.findViewById(R.id.message);
                    btn_title.setVisibility(View.VISIBLE);
                    btn_cancel.setText("我的头像");
                    btn_message.setText(msg);
                    final AlertDialog dialog = builder.create();
                    dialog.show();
                    dialog.getWindow().setContentView(view);
                    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                    dialog.setCancelable(false);
                    btn_sure.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            dialog.dismiss();
                            SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                                    Context.MODE_PRIVATE);
                            int faceRecgMark = sp.getInt("faceRecgMark", 0);
                            String photoUrl = sp.getString("photoUrl", "");
                            Bundle bundle = new Bundle();
                            bundle.putInt("faceRecgMark", faceRecgMark);
                            bundle.putString("photoUrl", photoUrl);
                            startActivityForResult(TakefacePhotoActivity.class, bundle, 0);

                        }
                    });
                    btn_cancel.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            dialog.dismiss();
                            showTakePhotoPopupWindow();
                        }
                    });
                }

            }
        } else if (faceRecgMark == 0) {
            if (isphoto) {
                SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                        Context.MODE_PRIVATE);
                if (photoMark == 1) {
                    re_course1.setVisibility(View.GONE);
                    show_camera_iv.setWillNotDraw(false);
                    show_camera_iv.setContentDescription(messageurl);
                    Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(messageurl);
                    show_camera_iv.setImageBitmap(bitmapByUrl);
                    SharedPreferences.Editor edit = sp.edit();
                    edit.putString("imgurl", imgurl);
                    edit.commit();
                } else if (photoMark == 2) {
                    re_course1.setVisibility(View.GONE);
                    if (show_camera_iv.getDrawable() == null) {
                        show_camera_iv.setWillNotDraw(false);
                        show_camera_iv.setContentDescription(messageurl);
                        Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(messageurl);
                        show_camera_iv.setImageBitmap(bitmapByUrl);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl", imgurl);
                        edit.commit();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() == null) {
                        show_camera_iv1.setWillNotDraw(false);
                        show_camera_iv1.setContentDescription(messageurl);
                        Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(messageurl);
                        show_camera_iv1.setImageBitmap(bitmapByUrl);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl1", imgurl);
                        edit.commit();
                    }
                } else if (photoMark == 3) {
                    re_course1.setVisibility(View.GONE);
                    if (show_camera_iv.getDrawable() == null) {
                        show_camera_iv.setWillNotDraw(false);
                        show_camera_iv.setContentDescription(messageurl);
                        Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(messageurl);
                        show_camera_iv.setImageBitmap(bitmapByUrl);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl", imgurl);
                        edit.commit();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() == null) {
                        show_camera_iv1.setWillNotDraw(false);
                        show_camera_iv1.setContentDescription(messageurl);
                        Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(messageurl);
                        show_camera_iv1.setImageBitmap(bitmapByUrl);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl1", imgurl);
                        edit.commit();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() != null && show_camera_iv2.getDrawable() == null) {
                        show_camera_iv2.setWillNotDraw(false);
                        show_camera_iv2.setContentDescription(messageurl);
                        Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(messageurl);
                        show_camera_iv2.setImageBitmap(bitmapByUrl);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl2", imgurl);
                        edit.commit();


                    }
                } else if (photoMark == 4) {
                    if (show_camera_iv.getDrawable() == null) {
                        re_course1.setVisibility(View.GONE);
                        show_camera_iv.setWillNotDraw(false);
                        show_camera_iv.setContentDescription(messageurl);
                        Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(messageurl);
                        show_camera_iv.setImageBitmap(bitmapByUrl);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl", imgurl);
                        edit.commit();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() == null) {
                        re_course1.setVisibility(View.GONE);
                        show_camera_iv1.setWillNotDraw(false);
                        show_camera_iv1.setContentDescription(messageurl);
                        Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(messageurl);
                        show_camera_iv1.setImageBitmap(bitmapByUrl);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl1", imgurl);
                        edit.commit();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() != null && show_camera_iv2.getDrawable() == null) {
                        re_course1.setVisibility(View.GONE);
                        show_camera_iv2.setWillNotDraw(false);
                        show_camera_iv2.setContentDescription(messageurl);
                        Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(messageurl);
                        show_camera_iv2.setImageBitmap(bitmapByUrl);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl2", imgurl);
                        edit.commit();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() != null && show_camera_iv2.getDrawable() != null && show_camera_iv3.getDrawable() == null) {
                        re_course1.setVisibility(View.VISIBLE);
                        show_camera_iv3.setWillNotDraw(false);
                        show_camera_iv3.setContentDescription(messageurl);
                        Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(messageurl);
                        show_camera_iv3.setImageBitmap(bitmapByUrl);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl3", imgurl);
                        edit.commit();
                    }
                } else if (photoMark == 5) {
                    if (show_camera_iv.getDrawable() == null) {
                        re_course1.setVisibility(View.GONE);
                        show_camera_iv.setWillNotDraw(false);
                        show_camera_iv.setContentDescription(messageurl);
                        Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(messageurl);
                        show_camera_iv.setImageBitmap(bitmapByUrl);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl", imgurl);
                        edit.commit();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() == null) {
                        re_course1.setVisibility(View.GONE);
                        show_camera_iv1.setWillNotDraw(false);
                        show_camera_iv1.setContentDescription(messageurl);
                        Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(messageurl);
                        show_camera_iv1.setImageBitmap(bitmapByUrl);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl1", imgurl);
                        edit.commit();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() != null && show_camera_iv2.getDrawable() == null) {
                        re_course1.setVisibility(View.GONE);
                        show_camera_iv2.setWillNotDraw(false);
                        show_camera_iv2.setContentDescription(messageurl);
                        Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(messageurl);
                        show_camera_iv2.setImageBitmap(bitmapByUrl);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl2", imgurl);
                        edit.commit();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() != null && show_camera_iv2.getDrawable() != null && show_camera_iv3.getDrawable() == null) {
                        re_course1.setVisibility(View.VISIBLE);
                        show_camera_iv3.setWillNotDraw(false);
                        show_camera_iv3.setContentDescription(messageurl);
                        Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(messageurl);
                        show_camera_iv3.setImageBitmap(bitmapByUrl);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl3", imgurl);
                        edit.commit();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() != null && show_camera_iv2.getDrawable() != null && show_camera_iv3.getDrawable() != null && show_camera_iv4.getDrawable() == null) {
                        re_course1.setVisibility(View.VISIBLE);
                        show_camera_iv4.setWillNotDraw(false);
                        show_camera_iv4.setContentDescription(messageurl);
                        Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(messageurl);
                        show_camera_iv4.setImageBitmap(bitmapByUrl);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl4", imgurl);
                        edit.commit();
                    }
                }
            } else {
                SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                        Context.MODE_PRIVATE);
                if (photoMark == 1) {
                    re_course1.setVisibility(View.GONE);
                    show_camera_iv.setWillNotDraw(true);
                    SharedPreferences.Editor edit = sp.edit();
                    edit.putString("imgurl", "");
                    edit.commit();
                    Toast.makeText(CourseDetailsActivity.this, "照片上传失败", Toast.LENGTH_LONG).show();
                } else if (photoMark == 2) {
                    re_course1.setVisibility(View.GONE);
                    if (show_camera_iv.getDrawable() == null) {
                        show_camera_iv.setWillNotDraw(true);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl", "");
                        edit.commit();
                        Toast.makeText(CourseDetailsActivity.this, "照片上传失败", Toast.LENGTH_LONG).show();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() == null) {
                        show_camera_iv1.setWillNotDraw(true);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl1", "");
                        edit.commit();
                        Toast.makeText(CourseDetailsActivity.this, "照片上传失败", Toast.LENGTH_LONG).show();
                    }
                } else if (photoMark == 3) {
                    re_course1.setVisibility(View.GONE);
                    if (show_camera_iv.getDrawable() == null) {
                        show_camera_iv.setWillNotDraw(true);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl", "");
                        edit.commit();
                        Toast.makeText(CourseDetailsActivity.this, "照片上传失败", Toast.LENGTH_LONG).show();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() == null) {
                        show_camera_iv1.setWillNotDraw(true);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl1", "");
                        edit.commit();
                        Toast.makeText(CourseDetailsActivity.this, "照片上传失败", Toast.LENGTH_LONG).show();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() != null && show_camera_iv2.getDrawable() == null) {
                        show_camera_iv2.setWillNotDraw(true);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl2", "");
                        edit.commit();
                        Toast.makeText(CourseDetailsActivity.this, "照片上传失败", Toast.LENGTH_LONG).show();
                    }
                } else if (photoMark == 4) {
                    if (show_camera_iv.getDrawable() == null) {
                        re_course1.setVisibility(View.GONE);
                        show_camera_iv.setWillNotDraw(true);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl", "");
                        edit.commit();
                        Toast.makeText(CourseDetailsActivity.this, "照片上传失败", Toast.LENGTH_LONG).show();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() == null) {
                        re_course1.setVisibility(View.GONE);
                        show_camera_iv1.setWillNotDraw(true);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl1", "");
                        edit.commit();
                        Toast.makeText(CourseDetailsActivity.this, "照片上传失败", Toast.LENGTH_LONG).show();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() != null && show_camera_iv2.getDrawable() == null) {
                        re_course1.setVisibility(View.GONE);
                        show_camera_iv2.setWillNotDraw(true);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl2", "");
                        edit.commit();
                        Toast.makeText(CourseDetailsActivity.this, "照片上传失败", Toast.LENGTH_LONG).show();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() != null && show_camera_iv2.getDrawable() != null && show_camera_iv3.getDrawable() == null) {
                        re_course1.setVisibility(View.VISIBLE);
                        show_camera_iv3.setWillNotDraw(true);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl3", "");
                        edit.commit();
                        Toast.makeText(CourseDetailsActivity.this, "照片上传失败", Toast.LENGTH_LONG).show();
                    }
                } else if (photoMark == 5) {
                    if (show_camera_iv.getDrawable() == null) {
                        re_course1.setVisibility(View.GONE);
                        show_camera_iv.setWillNotDraw(true);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl", "");
                        edit.commit();
                        Toast.makeText(CourseDetailsActivity.this, "照片上传失败", Toast.LENGTH_LONG).show();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() == null) {
                        re_course1.setVisibility(View.GONE);
                        show_camera_iv1.setWillNotDraw(true);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl1", "");
                        edit.commit();
                        Toast.makeText(CourseDetailsActivity.this, "照片上传失败", Toast.LENGTH_LONG).show();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() != null && show_camera_iv2.getDrawable() == null) {
                        re_course1.setVisibility(View.GONE);
                        show_camera_iv2.setWillNotDraw(true);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl2", "");
                        edit.commit();
                        Toast.makeText(CourseDetailsActivity.this, "照片上传失败", Toast.LENGTH_LONG).show();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() != null && show_camera_iv2.getDrawable() != null && show_camera_iv3.getDrawable() == null) {
                        re_course1.setVisibility(View.VISIBLE);
                        show_camera_iv3.setWillNotDraw(true);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl3", "");
                        edit.commit();
                        Toast.makeText(CourseDetailsActivity.this, "照片上传失败", Toast.LENGTH_LONG).show();
                    } else if (show_camera_iv.getDrawable() != null && show_camera_iv1.getDrawable() != null && show_camera_iv2.getDrawable() != null && show_camera_iv3.getDrawable() != null && show_camera_iv4.getDrawable() == null) {
                        re_course1.setVisibility(View.VISIBLE);
                        show_camera_iv4.setWillNotDraw(true);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("imgurl4", "");
                        edit.commit();
                        Toast.makeText(CourseDetailsActivity.this, "照片上传失败", Toast.LENGTH_LONG).show();
                    }
                }
            }
        }


//        if (imgurl != null) {
//            SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
//                    Context.MODE_PRIVATE);
//            SharedPreferences.Editor edit = sp.edit();
//            edit.putString("imgurl", imgurl);
//            edit.commit();
//        }
    }

    /**
     * 释放mCamera
     */
    private void releaseCamera() {
        if (mCamera != null) {
            mCamera.setPreviewCallback(null);
            mCamera.stopPreview();// 停掉原来摄像头的预览
            mCamera.release();
            mCamera = null;
        }
    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {

        setStartPreview(mCamera, mHolder);
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width,
                               int height) {
        // If your preview can change or rotate, take care of those events here.
        // Make sure to stop the preview before resizing or reformatting it.

        if (mHolder.getSurface() == null) {
            // preview surface does not exist
            return;
        }

        // stop preview before making changes
        try {
            mCamera.stopPreview();
        } catch (Exception e) {
            // ignore: tried to stop a non-existent preview
        }

        setStartPreview(mCamera, mHolder);

    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        // 当surfaceview关闭时，关闭预览并释放资源
        /**
         * 记得释放camera，方便其他应用调用
         */
        releaseCamera();
        holder = null;
        surfaceSv = null;
    }

    /**
     * 创建png图片回调数据对象
     */
//    Camera.PictureCallback picture = new Camera.PictureCallback() {
//        @Override
//        public void onPictureTaken(byte[] data, Camera camera) {
//            File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
//            if (pictureFile == null) {
//                Log.d(TAG,
//                        "Error creating media file, check storage permissions: ");
//                return;
//            }
//            try {
//                FileOutputStream fos = new FileOutputStream(pictureFile);
//                fos.write(data);
//                fos.close();
//
//                FileInputStream fis = new FileInputStream(pictureFile);
//                Bitmap bitmapByUrl = BitmapFactory.decodeStream(fis);
//
//                bitmapByUrl = compressScale(bitmapByUrl);
//
//                bitmapByUrl = rotaingImageView(-90, bitmapByUrl);
//
//                SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss ");
//                Date curDate = new Date(System.currentTimeMillis());//获取当前系统时间
//                String str = formatter.format(curDate);
//                Bitmap bitmap = ImageUtil.drawTextToLeftBottom(CourseDetailsActivity.this, bitmapByUrl, str, 8, Color.RED, 1, 1);
//
//                BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(pictureFile));
//                bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
//                bos.flush();
//                bos.close();
//
//                returnResult(pictureFile);
//            } catch (FileNotFoundException e) {
//                Log.d(TAG, "File not found: " + e.getMessage());
//            } catch (IOException e) {
//                Log.d(TAG, "Error accessing file: " + e.getMessage());
//            }
//        }
//    };

    /**
     * 图片按比例大小压缩方法
     *
     * @param image （根据Bitmap图片压缩）
     * @return
     */
//    public static Bitmap compressScale(Bitmap image) {
//        ByteArrayOutputStream baos = new ByteArrayOutputStream();
//        image.compress(Bitmap.CompressFormat.JPEG, 100, baos);
//        // 判断如果图片大于1M,进行压缩避免在生成图片（BitmapFactory.decodeStream）时溢出
//        if (baos.toByteArray().length / 1024 > 1024) {
//            baos.reset();// 重置baos即清空baos
//            image.compress(Bitmap.CompressFormat.JPEG, 80, baos);// 这里压缩50%，把压缩后的数据存放到baos中
//        }
//        ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray());
//        BitmapFactory.Options newOpts = new BitmapFactory.Options();
//        // 开始读入图片，此时把options.inJustDecodeBounds 设回true了
//        newOpts.inJustDecodeBounds = true;
//        Bitmap bitmap = BitmapFactory.decodeStream(isBm, null, newOpts);
//        newOpts.inJustDecodeBounds = false;
//        int w = newOpts.outWidth;
//        int h = newOpts.outHeight;
//        Log.i(TAG, w + "---------------" + h);
//        // 现在主流手机比较多是800*480分辨率，所以高和宽我们设置为
//        // float hh = 800f;// 这里设置高度为800f
//        // float ww = 480f;// 这里设置宽度为480f
//        float hh = 600f;
//        float ww = 450f;
//        // 缩放比。由于是固定比例缩放，只用高或者宽其中一个数据进行计算即可
//        int be = 1;// be=1表示不缩放
//        if (w > h && w > ww) {// 如果宽度大的话根据宽度固定大小缩放
//            be = (int) (newOpts.outWidth / ww);
//        } else if (w < h && h > hh) { // 如果高度高的话根据高度固定大小缩放
//            be = (int) (newOpts.outHeight / hh);
//        }
//        if (be <= 0)
//            be = 1;
//        newOpts.inSampleSize = be; // 设置缩放比例
//        // newOpts.inPreferredConfig = Config.RGB_565;//降低图片从ARGB888到RGB565
//        // 重新读入图片，注意此时已经把options.inJustDecodeBounds 设回false了
//        isBm = new ByteArrayInputStream(baos.toByteArray());
//        bitmap = BitmapFactory.decodeStream(isBm, null, newOpts);
//        return bitmap;
//        //return bitmap;
//    }

    //图片旋转
//    public static Bitmap rotaingImageView(int angle, Bitmap bitmap) {
//        //旋转图片 动作
//        Matrix matrix = new Matrix();
//        ;
//        matrix.postRotate(angle);
//        System.out.println("angle2=" + angle);
//        // 创建新的图片
//        Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0,
//                bitmap.getWidth(), bitmap.getHeight(), matrix, true);
//        return resizedBitmap;
//    }


    /**
     * Create a File for saving an image or video
     */
//    private static File getOutputMediaFile(int type) {
//        // To be safe, you should check that the SDCard is mounted
//        // using Environment.getExternalStorageState() before doing this.
//
//        File mediaStorageDir = new File(
//            Environment
//                    .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
//            "MyCameraApp");
//        // This location works best if you want the created images to be shared
//        // between applications and persist after your app has been uninstalled.
//
//        // Create the storage directory if it does not exist
//        if (!mediaStorageDir.exists()) {
//            if (!mediaStorageDir.mkdirs()) {
//                Log.d("MyCameraApp", "failed to create directory");
//                return null;
//            }
//        }
//        // Create a media file name
//        String timeStamp = HelpUtil.getDateFormatString(new Date());
//        File mediaFile;
//        if (type == MEDIA_TYPE_IMAGE) {
//            mediaFile = new File(mediaStorageDir.getPath() + File.separator
//                    + "IMG_" + timeStamp + ".png");
//        } else {
//            return null;
//        }
//        return mediaFile;
//    }

    /**
     * Check if this device has a camera
     */
    private boolean checkCameraHardware(Context context) {
        if (context.getPackageManager().hasSystemFeature(
                PackageManager.FEATURE_CAMERA)) {
            // this device has a camera
            return true;
        } else {
            // no camera on this device
            return false;
        }
    }

    /*****
     * 接受第二个Activity返回的数据时调用
     *
     * ****/
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        //super.onActivityResult(requestCode, resultCode, data);

        switch (requestCode) {
            case 0://拍第一张返回
                if (resultCode == 1) {
                    if (data == null) {
                        return;
                    }

                    String url = data.getStringExtra("url");
                    if (url != null && !TextUtils.isEmpty(url)) {
                        SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                                Context.MODE_PRIVATE);
                        String stringTime = sp.getString("format", "");
                        int index1 = stringTime.indexOf(":");
                        int index2 = stringTime.indexOf(":", index1 + 1);
                        int hh = Integer.parseInt(stringTime.substring(0, index1));
                        int mi = Integer.parseInt(stringTime.substring(index1 + 1, index2));
                        int ss = Integer.parseInt(stringTime.substring(index2 + 1));
                        int formatTurnSecond = hh * 60 * 60 + mi * 60 + ss;
                        subformatTurnSecond = formatTurnSecond + 1;//处理拍照时延迟1秒
                        String stringTime1 = getStringTime(subformatTurnSecond);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("format", stringTime1);
                        edit.putInt("tag", 1);
                        edit.commit();
                        if (photoMark == 1) {
                            Thread thread = new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
                                    mHandler.sendEmptyMessage(0);
                                }
                            });
                            thread.start();
                        } else if (photoMark == 2) {
                            Thread thread = new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
                                    mHandler.sendEmptyMessage(3);
                                }
                            });
                            thread.start();
                        } else if (photoMark == 3) {
                            Thread thread = new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
                                    mHandler.sendEmptyMessage(4);
                                }
                            });
                            thread.start();
                        } else if (photoMark == 4) {
                            Thread thread = new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
                                    mHandler.sendEmptyMessage(5);
                                }
                            });
                            thread.start();
                        } else if (photoMark == 5) {
                            Thread thread = new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
                                    mHandler.sendEmptyMessage(6);
                                }
                            });
                            thread.start();
                        }
                    }
                }
                break;
            case 1:
                if (resultCode == 1) {
                    final String url = data.getStringExtra("url");
                    SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                            Context.MODE_PRIVATE);
                    SharedPreferences.Editor edit = sp.edit();
                    edit.putString("photoUrl", url);
                    edit.commit();
                    AlertDialog.Builder builder = new AlertDialog.Builder(CourseDetailsActivity.this);
                    View view = View
                            .inflate(CourseDetailsActivity.this, R.layout.diolog_learn_person_layout, null);
                    TextView btn_sure = (TextView) view.findViewById(R.id.positiveButton);
                    TextView btn_cancel = (TextView) view.findViewById(R.id.negativeButton);
                    TextView btn_message = (TextView) view.findViewById(R.id.message);
                    TextView btn_title = (TextView) view.findViewById(R.id.title);
                    btn_title.setVisibility(View.INVISIBLE);
                    btn_message.setText("您已重新上传了个人头像，可点击“重新拍照”再次认证");
                    btn_cancel.setText("我的头像");
                    final AlertDialog dialog = builder.create();
                    dialog.show();
                    dialog.getWindow().setContentView(view);
                    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                    dialog.setCancelable(false);
                    btn_sure.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            dialog.dismiss();
                            SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                                    Context.MODE_PRIVATE);
                            int faceRecgMark = sp.getInt("faceRecgMark", 0);
                            Bundle bundle = new Bundle();
                            bundle.putInt("faceRecgMark", faceRecgMark);
                            bundle.putString("photoUrl", url);
                            startActivityForResult(TakefacePhotoActivity.class, bundle, 0);

                        }
                    });
                    btn_cancel.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            dialog.dismiss();
                            showTakePhotoPopupWindow();
                        }
                    });

                } else if (resultCode == 2) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(CourseDetailsActivity.this);
                    View view = View
                            .inflate(CourseDetailsActivity.this, R.layout.diolog_learn_person_layout, null);
                    TextView btn_sure = (TextView) view.findViewById(R.id.positiveButton);
                    TextView btn_cancel = (TextView) view.findViewById(R.id.negativeButton);
                    TextView btn_message = (TextView) view.findViewById(R.id.message);
                    TextView btn_title = (TextView) view.findViewById(R.id.title);
                    TextView btn_title1 = (TextView) view.findViewById(R.id.title1);
                    btn_title.setVisibility(View.INVISIBLE);
                    btn_title1.setText("请点我的头像！");
                    btn_message.setText("您上传了个人头像失败，可点击“我的头像”再次上传");
                    btn_cancel.setText("我的头像");
                    final AlertDialog dialog = builder.create();
                    dialog.show();
                    dialog.getWindow().setContentView(view);
                    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                    dialog.setCancelable(false);
                    btn_sure.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            dialog.dismiss();
                            SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                                    Context.MODE_PRIVATE);
                            int faceRecgMark = sp.getInt("faceRecgMark", 0);
                            String photoUrl = sp.getString("photoUrl", "");
                            Bundle bundle = new Bundle();
                            bundle.putInt("faceRecgMark", faceRecgMark);
                            bundle.putString("photoUrl", photoUrl);
                            startActivityForResult(TakefacePhotoActivity.class, bundle, 0);

                        }
                    });
                    btn_cancel.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            dialog.dismiss();
                            showTakePhotoPopupWindow();
                        }
                    });

                }

                break;
            case 2://拍第二张返回
                if (resultCode == 1) {
                    if (data == null) {
                        return;
                    }

                    String url = data.getStringExtra("url");
                    if (url != null && !TextUtils.isEmpty(url)) {
                        SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                                Context.MODE_PRIVATE);
                        String stringTime = sp.getString("format", "");
                        int index1 = stringTime.indexOf(":");
                        int index2 = stringTime.indexOf(":", index1 + 1);
                        int hh = Integer.parseInt(stringTime.substring(0, index1));
                        int mi = Integer.parseInt(stringTime.substring(index1 + 1, index2));
                        int ss = Integer.parseInt(stringTime.substring(index2 + 1));
                        int formatTurnSecond = hh * 60 * 60 + mi * 60 + ss;
                        subformatTurnSecond = formatTurnSecond + 1;//处理拍照时延迟1秒
                        String stringTime1 = getStringTime(subformatTurnSecond);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("format", stringTime1);
                        edit.putInt("tag", 1);
                        edit.commit();
                        if (photoMark == 2) {
                            Thread thread = new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
                                    mHandler.sendEmptyMessage(3);
                                }
                            });
                            thread.start();
                        } else if (photoMark == 3) {
                            Thread thread = new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
                                    mHandler.sendEmptyMessage(4);
                                }
                            });
                            thread.start();
                        } else if (photoMark == 4) {
                            Thread thread = new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
                                    mHandler.sendEmptyMessage(5);
                                }
                            });
                            thread.start();
                        } else if (photoMark == 5) {
                            Thread thread = new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
                                    mHandler.sendEmptyMessage(6);
                                }
                            });
                            thread.start();
                        }
                    }
                }
                break;
            case 3://拍第三张返回
                if (resultCode == 1) {
                    if (data == null) {
                        return;
                    }

                    String url = data.getStringExtra("url");
                    if (url != null && !TextUtils.isEmpty(url)) {
                        SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                                Context.MODE_PRIVATE);
                        String stringTime = sp.getString("format", "");
                        int index1 = stringTime.indexOf(":");
                        int index2 = stringTime.indexOf(":", index1 + 1);
                        int hh = Integer.parseInt(stringTime.substring(0, index1));
                        int mi = Integer.parseInt(stringTime.substring(index1 + 1, index2));
                        int ss = Integer.parseInt(stringTime.substring(index2 + 1));
                        int formatTurnSecond = hh * 60 * 60 + mi * 60 + ss;
                        subformatTurnSecond = formatTurnSecond + 1;//处理拍照时延迟1秒
                        String stringTime1 = getStringTime(subformatTurnSecond);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("format", stringTime1);
                        edit.putInt("tag", 1);
                        edit.commit();
                        if (photoMark == 3) {
                            Thread thread = new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
                                    mHandler.sendEmptyMessage(4);
                                }
                            });
                            thread.start();
                        } else if (photoMark == 4) {
                            Thread thread = new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
                                    mHandler.sendEmptyMessage(5);
                                }
                            });
                            thread.start();
                        } else if (photoMark == 5) {
                            Thread thread = new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
                                    mHandler.sendEmptyMessage(6);
                                }
                            });
                            thread.start();
                        }
                    }
                }
                break;
            case 4://拍第四张返回
                if (resultCode == 1) {
                    if (data == null) {
                        return;
                    }

                    String url = data.getStringExtra("url");
                    if (url != null && !TextUtils.isEmpty(url)) {
                        SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                                Context.MODE_PRIVATE);
                        String stringTime = sp.getString("format", "");
                        int index1 = stringTime.indexOf(":");
                        int index2 = stringTime.indexOf(":", index1 + 1);
                        int hh = Integer.parseInt(stringTime.substring(0, index1));
                        int mi = Integer.parseInt(stringTime.substring(index1 + 1, index2));
                        int ss = Integer.parseInt(stringTime.substring(index2 + 1));
                        int formatTurnSecond = hh * 60 * 60 + mi * 60 + ss;
                        subformatTurnSecond = formatTurnSecond + 1;//处理拍照时延迟1秒
                        String stringTime1 = getStringTime(subformatTurnSecond);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("format", stringTime1);
                        edit.putInt("tag", 1);
                        edit.commit();
                        if (photoMark == 4) {
                            Thread thread = new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
                                    mHandler.sendEmptyMessage(5);
                                }
                            });
                            thread.start();
                        } else if (photoMark == 5) {
                            Thread thread = new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
                                    mHandler.sendEmptyMessage(6);
                                }
                            });
                            thread.start();
                        }
                    }
                }
                break;
            case 5://拍第五张返回
                if (resultCode == 1) {
                    if (data == null) {
                        return;
                    }

                    String url = data.getStringExtra("url");
                    if (url != null && !TextUtils.isEmpty(url)) {
                        SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                                Context.MODE_PRIVATE);
                        String stringTime = sp.getString("format", "");
                        int index1 = stringTime.indexOf(":");
                        int index2 = stringTime.indexOf(":", index1 + 1);
                        int hh = Integer.parseInt(stringTime.substring(0, index1));
                        int mi = Integer.parseInt(stringTime.substring(index1 + 1, index2));
                        int ss = Integer.parseInt(stringTime.substring(index2 + 1));
                        int formatTurnSecond = hh * 60 * 60 + mi * 60 + ss;
                        subformatTurnSecond = formatTurnSecond + 1;//处理拍照时延迟1秒
                        String stringTime1 = getStringTime(subformatTurnSecond);
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putString("format", stringTime1);
                        edit.putInt("tag", 1);
                        edit.commit();
                        if (photoMark == 5) {
                            Thread thread = new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    //在子线程中执行任务，执行完成或需要通知UI线程时调用以下方法
                                    mHandler.sendEmptyMessage(6);
                                }
                            });
                            thread.start();
                        }
                    }
                }
                break;
        }
    }

    private void showTakePhotoPopupWindow() {

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        View view = View
                .inflate(CourseDetailsActivity.this, R.layout.diolog_photo_layout, null);
//                    TextView tv_message = (TextView) view
//                            .findViewById(R.id.message);//输入内容
//                    tv_message.setText("人脸识别失败,请面向镜头重新照相或者重新上传“我的”头像");
        SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                Context.MODE_PRIVATE);
        String photoUrl = sp.getString("photoUrl", "");
        ImageView img_photo = (ImageView) view.findViewById(R.id.img_photo2);
        if (!photoUrl.equals("")) {
            Picasso.with(CourseDetailsActivity.this).load(Uri.parse(photoUrl)).placeholder(R.mipmap.my_head).into(img_photo);//加载图片
        }
        TextView btn_PositiveButton = (TextView) view.findViewById(R.id.tv_photo6);//拍照
        TextView btn_NegativeButton = (TextView) view.findViewById(R.id.tv_photo5);//手机获取照片
        final AlertDialog dialog = builder.create();
        dialog.show();
        dialog.getWindow().setContentView(view);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        dialog.setCancelable(false);
        btn_PositiveButton.setOnClickListener(new View.OnClickListener() {//拍照
            @Override
            public void onClick(View view) {
                SharedPreferences sp = getSharedPreferences("CourseDetailsActivity",
                        Context.MODE_PRIVATE);
                SharedPreferences.Editor edit = sp.edit();
                edit.putInt("tag", 1);
                edit.commit();
                startActivityForResult(TakePersonPictureActivity.class, null, 1);
                dialog.dismiss();


            }
        });


    }
    /**
     * activity返回式返回拍照图片路径
     *
     * @param mediaFile
     */
//    private void returnResult(File mediaFile) {
//
//        Uri uri = Uri.fromFile(mediaFile);
//        String url = uri.toString().substring(uri.toString().indexOf("///") + 2);
//
//        if (url != null && !TextUtils.isEmpty(url)) {
//            show_camera_iv.setContentDescription(url);
//            Bitmap bitmapByUrl = HelpUtil.getBitmapByUrl(url);
//            show_camera_iv.setImageBitmap(bitmapByUrl);
//            mCamera.startPreview();
//        }
//        uploadImg(mediaFile);
//
//    }
//
//    private static final MediaType MEDIA_TYPE_PNG = MediaType.parse("image/png");
//    private final OkHttpClient client = new OkHttpClient();
//
//    private void uploadImg(File mediaFile) {
//
//        // mImgUrls为存放图片的url集合
//        MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM);
//
//        if (mediaFile != null) {
//            builder.addFormDataPart("headImg", mediaFile.getName(), RequestBody.create(MEDIA_TYPE_PNG, mediaFile));
//        }
//
//
//        MultipartBody requestBody = builder.build();
//        //构建请求
//        Request request = new Request.Builder()
//                .url(AppInterfaceConfig.BASE_URL + "app/course/uploadFromApp")//地址
//                .post(requestBody)//添加请求体
//                .build();
//
//        client.newCall(request).enqueue(new Callback() {
//            @Override
//            public void onFailure(Call call, IOException e) {
//                LogUtils.e("上传失败", e.getLocalizedMessage());
//
//            }
//
//            @Override
//            public void onResponse(Call call, Response response) throws IOException {
//
//
//                String str = response.body().string();
//                LogUtils.e("上传成功", str);
//                UpPhotoBean upPhotoBean = JSON.parseObject(str, UpPhotoBean.class);
//                String data = upPhotoBean.getData();
//                SharedPreferences sp = getSharedPreferences("imgurl",
//                        Context.MODE_PRIVATE);
//                SharedPreferences.Editor editor = sp.edit();
//                editor.putString("imgurl", data);
//                editor.commit();
//
//                //       Picasso.with(CourseDetailsActivity.this).load(Uri.parse(data)).into(show_camera_iv);//加载图片
//                LogUtils.e("上传图片", data);
//
//            }
//        });
//
//    }


    /**
     * 设置camera显示取景画面,并预览
     *
     * @param camera
     */
    private void setStartPreview(Camera camera, SurfaceHolder holder) {
        try {
            camera.setPreviewDisplay(holder);
            //开始预览
            camera.setDisplayOrientation(90);
            camera.startPreview();
        } catch (IOException e) {
            Log.d(TAG, "Error starting camera preview: " + e.getMessage());
        }
    }


    private void showAlertDialog(SuperFileView2 superFileView2, String url) {
        //1、使用Dialog、设置style
        //2、设置布局

        View contentView = LayoutInflater.from(CourseDetailsActivity.this).inflate(R.layout.dialog_circle, null);
        mDownloadPopWindow = new PopupWindow(contentView, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);

        mDownloadPopWindow.setContentView(contentView);
        mDownloadPopWindow.setFocusable(false);
        mDownloadPopWindow.setOutsideTouchable(false);
        mDownloadPopWindow.showAtLocation(contentView, Gravity.CENTER, 0, 0);


        CircularProgressView circularProgressView = contentView.findViewById(R.id.circleProgress);
        TextView textView = contentView.findViewById(R.id.progressTxt);
        TextView textView1 = contentView.findViewById(R.id.hintTxt);

        jumpingBeans2 = JumpingBeans.with(textView1)
                .makeTextJump(0, textView1.getText().length())
                .setIsWave(true)
                .setLoopDuration(3000)
                .build();

        downLoadFromNet(url, superFileView2, circularProgressView, textView);
    }

    private void downLoadFromNet(final String url, final SuperFileView2 superFileView, CircularProgressView circularProgressView, TextView tv1) {
        //showLoadingDialog("文件下载中...");
        //1.网络下载、存储路径、
        File cacheFile = FileParseUtil.getCacheFile(url);
        if (cacheFile.exists()) {
            if (cacheFile.length() <= 0) {
                cacheFile.delete();
                return;
            }
        }

        OkHttpClient okHttpClient = new OkHttpClient.Builder().connectTimeout(20, TimeUnit.SECONDS).readTimeout(20, TimeUnit.SECONDS).build();
        Request request = new Request.Builder().get().url(url).build();
        okHttpClient.newCall(request).enqueue(new okhttp3.Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                //请求成功,从服务器的响应对象中获取apk,流(服务器 输入流(提供数据)  本地 输出流(写入文件))
                ResponseBody body = response.body();
                //告知progressDialog总进度,不变
                //progressDialog.setMax((int) body.contentLength());
                final int allLength = (int) body.contentLength();
                //inputStream就是服务器把需要下载的apk以流的形式提供给客户端
                InputStream inputStream = body.byteStream();

                String fileName = url.substring(url.lastIndexOf("/"));
                String directory = Environment.getExternalStoragePublicDirectory
                        (Environment.DIRECTORY_DOWNLOADS).getPath();
                //File file = new File(directory+fileName);

                File file = FileParseUtil.getCacheFile(url);
                FileOutputStream fos = new FileOutputStream(file);
                byte[] bytes = new byte[1024];
                int len = 0;
                int temp = 0;//用于记录目前下载的到的位置
                while ((len = inputStream.read(bytes)) != -1) {
                    //将读过的数据写入文件中
                    fos.write(bytes, 0, len);
                    //告知progressDialog在下载过程中的当前进度
                    temp += len;
                    //将当前的下载位置,设置给progressDialog
                    //progressDialog.setProgress(temp);
                    //没下载一段数据,睡眠一段时间

                    int progress = (int) (temp * 100.0 / allLength);
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            circularProgressView.setProgress(progress);
                            tv1.setText(progress + "%");
                        }
                    });

                    try {
                        Thread.sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        //2.ACache记录文件的有效期
                        mDownloadPopWindow.dismiss();
                        superFileView.displayFile(file);
                    }
                });
            }
        });
    }
}
